Home | History | Annotate | Line # | Download | only in ssp
snprintf_chk.c revision 1.4.12.2
      1  1.4.12.2  kristerw /*	$NetBSD: snprintf_chk.c,v 1.4.12.2 2007/08/04 19:37:53 kristerw Exp $	*/
      2  1.4.12.2  kristerw 
      3  1.4.12.2  kristerw /*-
      4  1.4.12.2  kristerw  * Copyright (c) 2006 The NetBSD Foundation, Inc.
      5  1.4.12.2  kristerw  * All rights reserved.
      6  1.4.12.2  kristerw  *
      7  1.4.12.2  kristerw  * This code is derived from software contributed to The NetBSD Foundation
      8  1.4.12.2  kristerw  * by Christos Zoulas.
      9  1.4.12.2  kristerw  *
     10  1.4.12.2  kristerw  * Redistribution and use in source and binary forms, with or without
     11  1.4.12.2  kristerw  * modification, are permitted provided that the following conditions
     12  1.4.12.2  kristerw  * are met:
     13  1.4.12.2  kristerw  * 1. Redistributions of source code must retain the above copyright
     14  1.4.12.2  kristerw  *    notice, this list of conditions and the following disclaimer.
     15  1.4.12.2  kristerw  * 2. Redistributions in binary form must reproduce the above copyright
     16  1.4.12.2  kristerw  *    notice, this list of conditions and the following disclaimer in the
     17  1.4.12.2  kristerw  *    documentation and/or other materials provided with the distribution.
     18  1.4.12.2  kristerw  * 3. All advertising materials mentioning features or use of this software
     19  1.4.12.2  kristerw  *    must display the following acknowledgement:
     20  1.4.12.2  kristerw  *        This product includes software developed by the NetBSD
     21  1.4.12.2  kristerw  *        Foundation, Inc. and its contributors.
     22  1.4.12.2  kristerw  * 4. Neither the name of The NetBSD Foundation nor the names of its
     23  1.4.12.2  kristerw  *    contributors may be used to endorse or promote products derived
     24  1.4.12.2  kristerw  *    from this software without specific prior written permission.
     25  1.4.12.2  kristerw  *
     26  1.4.12.2  kristerw  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     27  1.4.12.2  kristerw  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     28  1.4.12.2  kristerw  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     29  1.4.12.2  kristerw  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     30  1.4.12.2  kristerw  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     31  1.4.12.2  kristerw  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     32  1.4.12.2  kristerw  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     33  1.4.12.2  kristerw  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     34  1.4.12.2  kristerw  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     35  1.4.12.2  kristerw  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     36  1.4.12.2  kristerw  * POSSIBILITY OF SUCH DAMAGE.
     37  1.4.12.2  kristerw  */
     38  1.4.12.2  kristerw #include <sys/cdefs.h>
     39  1.4.12.2  kristerw __RCSID("$NetBSD: snprintf_chk.c,v 1.4.12.2 2007/08/04 19:37:53 kristerw Exp $");
     40  1.4.12.2  kristerw 
     41  1.4.12.2  kristerw /*LINTLIBRARY*/
     42  1.4.12.2  kristerw 
     43  1.4.12.2  kristerw #include <ssp/ssp.h>
     44  1.4.12.2  kristerw #include <stdio.h>
     45  1.4.12.2  kristerw #include <stdarg.h>
     46  1.4.12.2  kristerw #include <ssp/stdio.h>
     47  1.4.12.2  kristerw 
     48  1.4.12.2  kristerw #undef vsnprintf
     49  1.4.12.2  kristerw 
     50  1.4.12.2  kristerw /*ARGSUSED*/
     51  1.4.12.2  kristerw int
     52  1.4.12.2  kristerw __snprintf_chk(char * __restrict buf, size_t len, int flags, size_t slen,
     53  1.4.12.2  kristerw     const char * __restrict fmt, ...)
     54  1.4.12.2  kristerw {
     55  1.4.12.2  kristerw 	va_list ap;
     56  1.4.12.2  kristerw 	int rv;
     57  1.4.12.2  kristerw 
     58  1.4.12.2  kristerw 	if (len > slen)
     59  1.4.12.2  kristerw 		__chk_fail();
     60  1.4.12.2  kristerw 
     61  1.4.12.2  kristerw 	va_start(ap, fmt);
     62  1.4.12.2  kristerw 	rv = vsnprintf(buf, len, fmt, ap);
     63  1.4.12.2  kristerw 	va_end(ap);
     64  1.4.12.2  kristerw 
     65  1.4.12.2  kristerw 	return rv;
     66  1.4.12.2  kristerw }
     67