Add a BSD-licensed re-implementation of the gcc-4.1 libssp.
This adds bounds checking for the following functions: memset, fgets, gets, memcpy, memmove, memset, snprintf, sprintf, strcat, strcpy, strncat, strncpy, vsnprintf, vsprintf This functionality is enabled by compiling with: gcc -I/usr/include/ssp -D_FORTIFY_SOURCE=<1|2> -lssp Eventually gcc will provide -ffortify-source or something to automate this [we hope :-)]
This commit is contained in:
parent
3f8c6dc981
commit
f499cd524a
17
lib/libssp/Makefile
Normal file
17
lib/libssp/Makefile
Normal file
@ -0,0 +1,17 @@
|
||||
# $NetBSD: Makefile,v 1.1 2006/11/08 19:52:11 christos Exp $
|
||||
|
||||
USE_SHLIBDIR= yes
|
||||
WARNS=4
|
||||
|
||||
CPPFLAGS+=-I${.CURDIR}/ssp
|
||||
LIB= ssp
|
||||
SRCS= gets_chk.c fgets_chk.c memcpy_chk.c memmove_chk.c memset_chk.c \
|
||||
snprintf_chk.c sprintf_chk.c strcat_chk.c strcpy_chk.c \
|
||||
strncat_chk.c strncpy_chk.c vsnprintf_chk.c vsprintf_chk.c
|
||||
|
||||
INCS= ssp/ssp.h ssp/stdio.h ssp/string.h ssp/unistd.h
|
||||
INCSDIR=/usr/include
|
||||
|
||||
.include <bsd.own.mk>
|
||||
.include <bsd.shlib.mk>
|
||||
.include <bsd.lib.mk>
|
57
lib/libssp/fgets_chk.c
Normal file
57
lib/libssp/fgets_chk.c
Normal file
@ -0,0 +1,57 @@
|
||||
/* $NetBSD: fgets_chk.c,v 1.1 2006/11/08 19:52:11 christos Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 2006 The NetBSD Foundation, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This code is derived from software contributed to The NetBSD Foundation
|
||||
* by Christos Zoulas.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. All advertising materials mentioning features or use of this software
|
||||
* must display the following acknowledgement:
|
||||
* This product includes software developed by the NetBSD
|
||||
* Foundation, Inc. and its contributors.
|
||||
* 4. Neither the name of The NetBSD Foundation nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
|
||||
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
||||
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
|
||||
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
#include <sys/cdefs.h>
|
||||
__RCSID("$NetBSD: fgets_chk.c,v 1.1 2006/11/08 19:52:11 christos Exp $");
|
||||
|
||||
#include <ssp.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <limits.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
char *
|
||||
__fgets_chk(char * __restrict buf, int len, size_t slen, FILE *fp)
|
||||
{
|
||||
if (slen >= (size_t)INT_MAX)
|
||||
return fgets(buf, len, fp);
|
||||
|
||||
if (len >= 0 && len > slen)
|
||||
__chk_fail();
|
||||
|
||||
return fgets(buf, len, fp);
|
||||
}
|
74
lib/libssp/gets_chk.c
Normal file
74
lib/libssp/gets_chk.c
Normal file
@ -0,0 +1,74 @@
|
||||
/* $NetBSD: gets_chk.c,v 1.1 2006/11/08 19:52:11 christos Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 2006 The NetBSD Foundation, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This code is derived from software contributed to The NetBSD Foundation
|
||||
* by Christos Zoulas.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. All advertising materials mentioning features or use of this software
|
||||
* must display the following acknowledgement:
|
||||
* This product includes software developed by the NetBSD
|
||||
* Foundation, Inc. and its contributors.
|
||||
* 4. Neither the name of The NetBSD Foundation nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
|
||||
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
||||
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
|
||||
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
#include <sys/cdefs.h>
|
||||
__RCSID("$NetBSD: gets_chk.c,v 1.1 2006/11/08 19:52:11 christos Exp $");
|
||||
|
||||
#include <ssp.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <limits.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
char *
|
||||
__gets_chk(char * __restrict buf, size_t slen)
|
||||
{
|
||||
char *abuf;
|
||||
size_t len;
|
||||
|
||||
if (slen >= (size_t)INT_MAX)
|
||||
return gets(buf);
|
||||
|
||||
if ((abuf = malloc(slen + 1)) == NULL)
|
||||
return gets(buf);
|
||||
|
||||
if (fgets(abuf, (int)(slen + 1), stdin) == NULL)
|
||||
return NULL;
|
||||
|
||||
len = strlen(abuf);
|
||||
if (len > 0 && abuf[len - 1] == '\n')
|
||||
--len;
|
||||
|
||||
if (len >= slen)
|
||||
__chk_fail();
|
||||
|
||||
(void)memcpy(buf, abuf, len);
|
||||
|
||||
buf[len] = '\0';
|
||||
free(abuf);
|
||||
return buf;
|
||||
}
|
51
lib/libssp/memcpy_chk.c
Normal file
51
lib/libssp/memcpy_chk.c
Normal file
@ -0,0 +1,51 @@
|
||||
/* $NetBSD: memcpy_chk.c,v 1.1 2006/11/08 19:52:11 christos Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 2006 The NetBSD Foundation, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This code is derived from software contributed to The NetBSD Foundation
|
||||
* by Christos Zoulas.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. All advertising materials mentioning features or use of this software
|
||||
* must display the following acknowledgement:
|
||||
* This product includes software developed by the NetBSD
|
||||
* Foundation, Inc. and its contributors.
|
||||
* 4. Neither the name of The NetBSD Foundation nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
|
||||
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
||||
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
|
||||
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
#include <sys/cdefs.h>
|
||||
__RCSID("$NetBSD: memcpy_chk.c,v 1.1 2006/11/08 19:52:11 christos Exp $");
|
||||
|
||||
#include <ssp.h>
|
||||
#include <string.h>
|
||||
|
||||
void *
|
||||
__memcpy_chk(void * __restrict dst, const void * __restrict src, size_t len,
|
||||
size_t slen)
|
||||
{
|
||||
if (len > slen)
|
||||
__chk_fail();
|
||||
return memcpy(dst, src, len);
|
||||
}
|
51
lib/libssp/memmove_chk.c
Normal file
51
lib/libssp/memmove_chk.c
Normal file
@ -0,0 +1,51 @@
|
||||
/* $NetBSD: memmove_chk.c,v 1.1 2006/11/08 19:52:11 christos Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 2006 The NetBSD Foundation, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This code is derived from software contributed to The NetBSD Foundation
|
||||
* by Christos Zoulas.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. All advertising materials mentioning features or use of this software
|
||||
* must display the following acknowledgement:
|
||||
* This product includes software developed by the NetBSD
|
||||
* Foundation, Inc. and its contributors.
|
||||
* 4. Neither the name of The NetBSD Foundation nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
|
||||
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
||||
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
|
||||
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
#include <sys/cdefs.h>
|
||||
__RCSID("$NetBSD: memmove_chk.c,v 1.1 2006/11/08 19:52:11 christos Exp $");
|
||||
|
||||
#include <ssp.h>
|
||||
#include <string.h>
|
||||
|
||||
void *
|
||||
__memmove_chk(void *dst, void *src, size_t len,
|
||||
size_t slen)
|
||||
{
|
||||
if (len > slen)
|
||||
__chk_fail();
|
||||
return memmove(dst, src, len);
|
||||
}
|
50
lib/libssp/memset_chk.c
Normal file
50
lib/libssp/memset_chk.c
Normal file
@ -0,0 +1,50 @@
|
||||
/* $NetBSD: memset_chk.c,v 1.1 2006/11/08 19:52:11 christos Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 2006 The NetBSD Foundation, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This code is derived from software contributed to The NetBSD Foundation
|
||||
* by Christos Zoulas.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. All advertising materials mentioning features or use of this software
|
||||
* must display the following acknowledgement:
|
||||
* This product includes software developed by the NetBSD
|
||||
* Foundation, Inc. and its contributors.
|
||||
* 4. Neither the name of The NetBSD Foundation nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
|
||||
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
||||
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
|
||||
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
#include <sys/cdefs.h>
|
||||
__RCSID("$NetBSD: memset_chk.c,v 1.1 2006/11/08 19:52:11 christos Exp $");
|
||||
|
||||
#include <ssp.h>
|
||||
#include <string.h>
|
||||
|
||||
void *
|
||||
__memset_chk(void * __restrict dst, int val, size_t len, size_t slen)
|
||||
{
|
||||
if (len > slen)
|
||||
__chk_fail();
|
||||
return memset(dst, val, len);
|
||||
}
|
61
lib/libssp/snprintf_chk.c
Normal file
61
lib/libssp/snprintf_chk.c
Normal file
@ -0,0 +1,61 @@
|
||||
/* $NetBSD: snprintf_chk.c,v 1.1 2006/11/08 19:52:11 christos Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 2006 The NetBSD Foundation, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This code is derived from software contributed to The NetBSD Foundation
|
||||
* by Christos Zoulas.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. All advertising materials mentioning features or use of this software
|
||||
* must display the following acknowledgement:
|
||||
* This product includes software developed by the NetBSD
|
||||
* Foundation, Inc. and its contributors.
|
||||
* 4. Neither the name of The NetBSD Foundation nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
|
||||
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
||||
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
|
||||
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
#include <sys/cdefs.h>
|
||||
__RCSID("$NetBSD: snprintf_chk.c,v 1.1 2006/11/08 19:52:11 christos Exp $");
|
||||
|
||||
#include <ssp.h>
|
||||
#include <stdio.h>
|
||||
#include <stdarg.h>
|
||||
|
||||
/*ARGSUSED*/
|
||||
int
|
||||
__snprintf_chk(char * __restrict buf, size_t len, int flags, size_t slen,
|
||||
const char * __restrict fmt, ...)
|
||||
{
|
||||
va_list ap;
|
||||
int rv;
|
||||
|
||||
if (len > slen)
|
||||
__chk_fail();
|
||||
|
||||
va_start(ap, fmt);
|
||||
rv = vsnprintf(buf, len, fmt, ap);
|
||||
va_end(ap);
|
||||
|
||||
return rv;
|
||||
}
|
64
lib/libssp/sprintf_chk.c
Normal file
64
lib/libssp/sprintf_chk.c
Normal file
@ -0,0 +1,64 @@
|
||||
/* $NetBSD: sprintf_chk.c,v 1.1 2006/11/08 19:52:11 christos Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 2006 The NetBSD Foundation, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This code is derived from software contributed to The NetBSD Foundation
|
||||
* by Christos Zoulas.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. All advertising materials mentioning features or use of this software
|
||||
* must display the following acknowledgement:
|
||||
* This product includes software developed by the NetBSD
|
||||
* Foundation, Inc. and its contributors.
|
||||
* 4. Neither the name of The NetBSD Foundation nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
|
||||
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
||||
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
|
||||
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
#include <sys/cdefs.h>
|
||||
__RCSID("$NetBSD: sprintf_chk.c,v 1.1 2006/11/08 19:52:11 christos Exp $");
|
||||
|
||||
#include <ssp.h>
|
||||
#include <stdio.h>
|
||||
#include <limits.h>
|
||||
#include <stdarg.h>
|
||||
|
||||
int
|
||||
/*ARGSUSED*/
|
||||
__sprintf_chk(char * __restrict buf, int flags, size_t slen,
|
||||
const char * __restrict fmt, ...)
|
||||
{
|
||||
va_list ap;
|
||||
int rv;
|
||||
|
||||
va_start(ap, fmt);
|
||||
if (slen > (size_t)INT_MAX)
|
||||
rv = vsprintf(buf, fmt, ap);
|
||||
else {
|
||||
if ((rv = vsnprintf(buf, slen, fmt, ap)) >= 0 && rv >= slen)
|
||||
__chk_fail();
|
||||
}
|
||||
va_end(ap);
|
||||
|
||||
return rv;
|
||||
}
|
74
lib/libssp/ssp/ssp.h
Normal file
74
lib/libssp/ssp/ssp.h
Normal file
@ -0,0 +1,74 @@
|
||||
/* $NetBSD: ssp.h,v 1.1 2006/11/08 19:52:11 christos Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 2006 The NetBSD Foundation, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This code is derived from software contributed to The NetBSD Foundation
|
||||
* by Christos Zoulas.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. All advertising materials mentioning features or use of this software
|
||||
* must display the following acknowledgement:
|
||||
* This product includes software developed by the NetBSD
|
||||
* Foundation, Inc. and its contributors.
|
||||
* 4. Neither the name of The NetBSD Foundation nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
|
||||
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
||||
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
|
||||
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
#ifndef _SSP_SSP_H_
|
||||
#define _SSP_SSP_H_
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
|
||||
#if !defined(__cplusplus)
|
||||
# if _FORTIFY_SOURCE > 0 && __OPTIMIZE__ > 0 && __GNUC_PREREQ__(4, 1)
|
||||
# if _FORTIFY_SOURCE > 1
|
||||
# define __SSP_FORTIFY_LEVEL 2
|
||||
# else
|
||||
# define __SSP_FORTIFY_LEVEL 1
|
||||
# endif
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#define __ssp_bos(ptr) __builtin_object_size(ptr, __SSP_FORTIFY_LEVEL > 1)
|
||||
#define __ssp_bos0(ptr) __builtin_object_size(ptr, 0)
|
||||
#define __ssp_redirect_raw(rtype, fun, args, call, bos) \
|
||||
inline __attribute__((__always_inline__)) rtype __ ## fun ## _alias args; \
|
||||
inline __attribute__((__always_inline__)) rtype \
|
||||
__ ## fun ## _alias args { \
|
||||
if (bos(__buf) != (size_t)-1 && __len > bos(__buf)) \
|
||||
__chk_fail(); \
|
||||
return fun call; \
|
||||
}
|
||||
|
||||
#define __ssp_redirect(rtype, fun, args, call) \
|
||||
__ssp_redirect_raw(rtype, fun, args, call, __ssp_bos)
|
||||
#define __ssp_redirect0(rtype, fun, args, call) \
|
||||
__ssp_redirect_raw(rtype, fun, args, call, __ssp_bos0)
|
||||
|
||||
__BEGIN_DECLS
|
||||
void __stack_chk_fail(void) __attribute__((__noreturn__));
|
||||
void __chk_fail(void) __attribute__((__noreturn__));
|
||||
__END_DECLS
|
||||
|
||||
#endif /* _SSP_SSP_H_ */
|
79
lib/libssp/ssp/stdio.h
Normal file
79
lib/libssp/ssp/stdio.h
Normal file
@ -0,0 +1,79 @@
|
||||
/* $NetBSD: stdio.h,v 1.1 2006/11/08 19:52:11 christos Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 2006 The NetBSD Foundation, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This code is derived from software contributed to The NetBSD Foundation
|
||||
* by Christos Zoulas.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. All advertising materials mentioning features or use of this software
|
||||
* must display the following acknowledgement:
|
||||
* This product includes software developed by the NetBSD
|
||||
* Foundation, Inc. and its contributors.
|
||||
* 4. Neither the name of The NetBSD Foundation nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
|
||||
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
||||
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
|
||||
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
#ifndef _SSP_STDIO_H_
|
||||
#define _SSP_STDIO_H_
|
||||
|
||||
#include <ssp.h>
|
||||
#include_next <stdio.h>
|
||||
|
||||
__BEGIN_DECLS
|
||||
int __sprintf_chk(char *__restrict, int, size_t, const char *__restrict, ...)
|
||||
__attribute__((__format__(__printf__, 4, 5)));
|
||||
int __vsprintf_chk(char *__restrict, int, size_t, const char *__restrict,
|
||||
_BSD_VA_LIST_) __attribute__((__format__(__printf__, 4, 0)));
|
||||
int __snprintf_chk(char *__restrict, size_t, int, size_t,
|
||||
const char *__restrict, ...) __attribute__((__format__(__printf__, 5, 6)));
|
||||
int __vnsprintf_chk(char *__restrict, int, size_t, const char *__restrict,
|
||||
_BSD_VA_LIST_) __attribute__((__format__(__printf__, 5, 0)));
|
||||
char *__gets_chk(char *, size_t);
|
||||
char *__fgets_chk(char *, int, size_t, FILE *);
|
||||
__END_DECLS
|
||||
|
||||
#if __SSP_FORTIFY_LEVEL > 0
|
||||
|
||||
|
||||
#define sprintf(str, ...) \
|
||||
__builtin___sprintf_chk(str, 0, __ssp_bos(str), __VA_ARGS__)
|
||||
|
||||
#define vsprintf(str, fmt, ap) \
|
||||
__builtin___vsprintf_chk(str, 0, __ssp_bos(str), fmt, ap)
|
||||
|
||||
#define snprintf(str, len, ...) \
|
||||
__builtin___snprintf_chk(str, len, 0, __ssp_bos(str), __VA_ARGS__)
|
||||
|
||||
#define vsnprintf(str, len, fmt, ap) \
|
||||
__builtin___vsnprintf_chk(str, len, 0, __ssp_bos(str), fmt, ap)
|
||||
|
||||
#define gets(str) \
|
||||
__gets_chk(str, __ssp_bos(str))
|
||||
|
||||
#define fgets(str, len, fp) \
|
||||
__fgets_chk(str, len, __ssp_bos(str), fp)
|
||||
#endif /* __SSP_FORTIFY_LEVEL > 0 */
|
||||
|
||||
#endif /* _SSP_STDIO_H_ */
|
104
lib/libssp/ssp/string.h
Normal file
104
lib/libssp/ssp/string.h
Normal file
@ -0,0 +1,104 @@
|
||||
/* $NetBSD: string.h,v 1.1 2006/11/08 19:52:11 christos Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 2006 The NetBSD Foundation, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This code is derived from software contributed to The NetBSD Foundation
|
||||
* by Christos Zoulas.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. All advertising materials mentioning features or use of this software
|
||||
* must display the following acknowledgement:
|
||||
* This product includes software developed by the NetBSD
|
||||
* Foundation, Inc. and its contributors.
|
||||
* 4. Neither the name of The NetBSD Foundation nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
|
||||
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
||||
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
|
||||
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
#ifndef _SSP_STRING_H_
|
||||
#define _SSP_STRING_H_
|
||||
|
||||
#include <ssp.h>
|
||||
#include_next <string.h>
|
||||
|
||||
#if __SSP_FORTIFY_LEVEL > 0
|
||||
|
||||
#define __ssp_bos_check3(fun, dst, src, len) \
|
||||
((__ssp_bos0(dst) != (size_t)-1) ? \
|
||||
__builtin___ ## fun ## _chk(dst, src, len, __ssp_bos0(dst)) : \
|
||||
__ ## fun ## _ichk(dst, src, len))
|
||||
|
||||
#define __ssp_bos_check2(fun, dst, src) \
|
||||
((__ssp_bos0(dst) != (size_t)-1) ? \
|
||||
__builtin___ ## fun ## _chk(dst, src, __ssp_bos0(dst)) : \
|
||||
__ ## fun ## _ichk(dst, src))
|
||||
|
||||
#define __ssp_bos_icheck3_restrict(fun, type1, type2) \
|
||||
type1 __ ## fun ## _ichk(type1 __restrict, type2 __restrict, size_t); \
|
||||
inline __attribute__((__always_inline__)) type1 \
|
||||
__ ## fun ## _ichk(type1 __restrict dst, type2 __restrict src, size_t len) { \
|
||||
return __builtin___ ## fun ## _chk(dst, src, len, __ssp_bos0(dst)); \
|
||||
}
|
||||
|
||||
#define __ssp_bos_icheck3(fun, type1, type2) \
|
||||
type1 __ ## fun ## _ichk(type1, type2, size_t); \
|
||||
inline __attribute__((__always_inline__)) type1 \
|
||||
__ ## fun ## _ichk(type1 dst, type2 src, size_t len) { \
|
||||
return __builtin___ ## fun ## _chk(dst, src, len, __ssp_bos0(dst)); \
|
||||
}
|
||||
|
||||
#define __ssp_bos_icheck2_restrict(fun, type1, type2) \
|
||||
type1 __ ## fun ## _ichk(type1, type2); \
|
||||
inline __attribute__((__always_inline__)) type1 \
|
||||
__ ## fun ## _ichk(type1 __restrict dst, type2 __restrict src) { \
|
||||
return __builtin___ ## fun ## _chk(dst, src, __ssp_bos0(dst)); \
|
||||
}
|
||||
|
||||
__BEGIN_DECLS
|
||||
__ssp_bos_icheck3_restrict(memcpy, void *, const void *)
|
||||
__ssp_bos_icheck3(memmove, void *, const void *)
|
||||
__ssp_bos_icheck3(memset, void *, int)
|
||||
__ssp_bos_icheck2_restrict(strcpy, char *, const char *)
|
||||
__ssp_bos_icheck2_restrict(strcat, char *, const char *)
|
||||
__ssp_bos_icheck3_restrict(strncpy, char *, const char *)
|
||||
__ssp_bos_icheck3_restrict(strncat, char *, const char *)
|
||||
__END_DECLS
|
||||
|
||||
#define memcpy(dst, src, len) __ssp_bos_check3(memcpy, dst, src, len)
|
||||
#define memmove(dst, src, len) __ssp_bos_check3(memmove, dst, src, len)
|
||||
#define memset(dst, val, len) __ssp_bos_check3(memset, dst, val, len)
|
||||
#define bcopy(src, dst, len) \
|
||||
((__ssp_bos0(dst) != (size_t)-1) ? \
|
||||
__builtin___memmove_chk(dst, src, __ssp_bos0(dst)) : \
|
||||
__memmove_ichk(dst, src, len))
|
||||
#define bzero(dst, len) \
|
||||
((__ssp_bos0(dst) != (size_t)-1) ? \
|
||||
__builtin___memset_chk(dst, 0, __ssp_bos0(dst)) : \
|
||||
__memset_ichk(dst, src, len))
|
||||
#define strcpy(dst, src) __ssp_bos_check2(strcpy, dst, src)
|
||||
#define strcat(dst, src) __ssp_bos_check2(strcat, dst, src)
|
||||
#define strncpy(dst, src, lne) __ssp_bos_check3(strncpy, dst, src, len)
|
||||
#define strncat(dst, src, lne) __ssp_bos_check3(strncat, dst, src, len)
|
||||
|
||||
#endif /* __SSP_FORTIFY_LEVEL > 0 */
|
||||
#endif /* _SSP_STRING_H_ */
|
63
lib/libssp/ssp/unistd.h
Normal file
63
lib/libssp/ssp/unistd.h
Normal file
@ -0,0 +1,63 @@
|
||||
/* $NetBSD: unistd.h,v 1.1 2006/11/08 19:52:11 christos Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 2006 The NetBSD Foundation, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This code is derived from software contributed to The NetBSD Foundation
|
||||
* by Christos Zoulas.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. All advertising materials mentioning features or use of this software
|
||||
* must display the following acknowledgement:
|
||||
* This product includes software developed by the NetBSD
|
||||
* Foundation, Inc. and its contributors.
|
||||
* 4. Neither the name of The NetBSD Foundation nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
|
||||
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
||||
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
|
||||
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
#ifndef _SSP_UNISTD_H_
|
||||
#define _SSP_UNISTD_H_
|
||||
|
||||
#include <ssp.h>
|
||||
|
||||
#include_next <unistd.h>
|
||||
|
||||
#if __SSP_FORTIFY_LEVEL > 0
|
||||
__BEGIN_DECLS
|
||||
|
||||
__ssp_redirect0(ssize_t, read, (int __fd, void *__buf, size_t __len), \
|
||||
(__fd, __buf, __len));
|
||||
|
||||
__ssp_redirect(int, readlink, (const char *__restrict __path, \
|
||||
char *__restrict __buf, size_t __len), (__path, __buf, __len));
|
||||
|
||||
__ssp_redirect(char *, getcwd, (char *__buf, size_t __len), (__buf, __len));
|
||||
|
||||
__END_DECLS
|
||||
|
||||
#define read(fd, buf, len) __read_alias(fd, buf, len)
|
||||
#define readlink(path, buf, len) __readlink_alias(path, buf, len)
|
||||
#define getcwd(buf, len) __getcwd_alias(buf, len)
|
||||
|
||||
#endif /* __SSP_FORTIFY_LEVEL > 0 */
|
||||
#endif /* _SSP_UNISTD_H_ */
|
65
lib/libssp/strcat_chk.c
Normal file
65
lib/libssp/strcat_chk.c
Normal file
@ -0,0 +1,65 @@
|
||||
/* $NetBSD: strcat_chk.c,v 1.1 2006/11/08 19:52:11 christos Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 2006 The NetBSD Foundation, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This code is derived from software contributed to The NetBSD Foundation
|
||||
* by Christos Zoulas.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. All advertising materials mentioning features or use of this software
|
||||
* must display the following acknowledgement:
|
||||
* This product includes software developed by the NetBSD
|
||||
* Foundation, Inc. and its contributors.
|
||||
* 4. Neither the name of The NetBSD Foundation nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
|
||||
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
||||
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
|
||||
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
#include <sys/cdefs.h>
|
||||
__RCSID("$NetBSD: strcat_chk.c,v 1.1 2006/11/08 19:52:11 christos Exp $");
|
||||
|
||||
#include <ssp.h>
|
||||
#include <string.h>
|
||||
|
||||
char *
|
||||
__strcat_chk(char * __restrict dst, char * __restrict src, size_t slen)
|
||||
{
|
||||
char *d;
|
||||
|
||||
for (d = dst; *d; d++) {
|
||||
if (slen-- == 0)
|
||||
__chk_fail();
|
||||
}
|
||||
|
||||
while (*src) {
|
||||
if (slen-- == 0)
|
||||
__chk_fail();
|
||||
*d++ = *src++;
|
||||
}
|
||||
|
||||
if (slen-- == 0)
|
||||
__chk_fail();
|
||||
|
||||
*d = '\0';
|
||||
return dst;
|
||||
}
|
53
lib/libssp/strcpy_chk.c
Normal file
53
lib/libssp/strcpy_chk.c
Normal file
@ -0,0 +1,53 @@
|
||||
/* $NetBSD: strcpy_chk.c,v 1.1 2006/11/08 19:52:11 christos Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 2006 The NetBSD Foundation, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This code is derived from software contributed to The NetBSD Foundation
|
||||
* by Christos Zoulas.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. All advertising materials mentioning features or use of this software
|
||||
* must display the following acknowledgement:
|
||||
* This product includes software developed by the NetBSD
|
||||
* Foundation, Inc. and its contributors.
|
||||
* 4. Neither the name of The NetBSD Foundation nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
|
||||
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
||||
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
|
||||
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
#include <sys/cdefs.h>
|
||||
__RCSID("$NetBSD: strcpy_chk.c,v 1.1 2006/11/08 19:52:11 christos Exp $");
|
||||
|
||||
#include <ssp.h>
|
||||
#include <string.h>
|
||||
|
||||
char *
|
||||
__strcpy_chk(char * __restrict dst, const char * __restrict src, size_t slen)
|
||||
{
|
||||
size_t len = strlen(src);
|
||||
|
||||
if (len > slen)
|
||||
__chk_fail();
|
||||
|
||||
return memcpy(dst, src, len + 1);
|
||||
}
|
75
lib/libssp/strncat_chk.c
Normal file
75
lib/libssp/strncat_chk.c
Normal file
@ -0,0 +1,75 @@
|
||||
/* $NetBSD: strncat_chk.c,v 1.1 2006/11/08 19:52:11 christos Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 2006 The NetBSD Foundation, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This code is derived from software contributed to The NetBSD Foundation
|
||||
* by Christos Zoulas.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. All advertising materials mentioning features or use of this software
|
||||
* must display the following acknowledgement:
|
||||
* This product includes software developed by the NetBSD
|
||||
* Foundation, Inc. and its contributors.
|
||||
* 4. Neither the name of The NetBSD Foundation nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
|
||||
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
||||
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
|
||||
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
#include <sys/cdefs.h>
|
||||
__RCSID("$NetBSD: strncat_chk.c,v 1.1 2006/11/08 19:52:11 christos Exp $");
|
||||
|
||||
#include <ssp.h>
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
|
||||
char *
|
||||
__strncat_chk(char * __restrict dst, char * __restrict src, size_t len,
|
||||
size_t slen)
|
||||
{
|
||||
char *d;
|
||||
|
||||
if (len == 0)
|
||||
return dst;
|
||||
|
||||
if (len > slen)
|
||||
__chk_fail();
|
||||
|
||||
for (d = dst; *d; d++) {
|
||||
if (slen-- == 0)
|
||||
__chk_fail();
|
||||
}
|
||||
|
||||
do {
|
||||
if ((*d = *src++) == '\0')
|
||||
break;
|
||||
if (slen-- == 0)
|
||||
__chk_fail();
|
||||
d++;
|
||||
} while (--len != 0);
|
||||
|
||||
if (slen-- == 0)
|
||||
__chk_fail();
|
||||
|
||||
*d = '\0';
|
||||
return dst;
|
||||
}
|
52
lib/libssp/strncpy_chk.c
Normal file
52
lib/libssp/strncpy_chk.c
Normal file
@ -0,0 +1,52 @@
|
||||
/* $NetBSD: strncpy_chk.c,v 1.1 2006/11/08 19:52:11 christos Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 2006 The NetBSD Foundation, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This code is derived from software contributed to The NetBSD Foundation
|
||||
* by Christos Zoulas.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. All advertising materials mentioning features or use of this software
|
||||
* must display the following acknowledgement:
|
||||
* This product includes software developed by the NetBSD
|
||||
* Foundation, Inc. and its contributors.
|
||||
* 4. Neither the name of The NetBSD Foundation nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
|
||||
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
||||
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
|
||||
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
#include <sys/cdefs.h>
|
||||
__RCSID("$NetBSD: strncpy_chk.c,v 1.1 2006/11/08 19:52:11 christos Exp $");
|
||||
|
||||
#include <ssp.h>
|
||||
#include <string.h>
|
||||
|
||||
char *
|
||||
__strncpy_chk(char * __restrict dst, const char * __restrict src, size_t len,
|
||||
size_t slen)
|
||||
{
|
||||
if (len > slen)
|
||||
__chk_fail();
|
||||
|
||||
return strncpy(dst, src, len);
|
||||
}
|
53
lib/libssp/vsnprintf_chk.c
Normal file
53
lib/libssp/vsnprintf_chk.c
Normal file
@ -0,0 +1,53 @@
|
||||
/* $NetBSD: vsnprintf_chk.c,v 1.1 2006/11/08 19:52:11 christos Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 2006 The NetBSD Foundation, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This code is derived from software contributed to The NetBSD Foundation
|
||||
* by Christos Zoulas.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. All advertising materials mentioning features or use of this software
|
||||
* must display the following acknowledgement:
|
||||
* This product includes software developed by the NetBSD
|
||||
* Foundation, Inc. and its contributors.
|
||||
* 4. Neither the name of The NetBSD Foundation nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
|
||||
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
||||
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
|
||||
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
#include <sys/cdefs.h>
|
||||
__RCSID("$NetBSD: vsnprintf_chk.c,v 1.1 2006/11/08 19:52:11 christos Exp $");
|
||||
|
||||
#include <ssp.h>
|
||||
#include <stdio.h>
|
||||
#include <stdarg.h>
|
||||
|
||||
int
|
||||
__vsnprintf_chk(char * __restrict buf, size_t len, int flags, size_t slen,
|
||||
const char * __restrict fmt, va_list ap)
|
||||
{
|
||||
if (len > slen)
|
||||
__chk_fail();
|
||||
|
||||
return vsnprintf(buf, len, fmt, ap);
|
||||
}
|
61
lib/libssp/vsprintf_chk.c
Normal file
61
lib/libssp/vsprintf_chk.c
Normal file
@ -0,0 +1,61 @@
|
||||
/* $NetBSD: vsprintf_chk.c,v 1.1 2006/11/08 19:52:11 christos Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 2006 The NetBSD Foundation, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This code is derived from software contributed to The NetBSD Foundation
|
||||
* by Christos Zoulas.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. All advertising materials mentioning features or use of this software
|
||||
* must display the following acknowledgement:
|
||||
* This product includes software developed by the NetBSD
|
||||
* Foundation, Inc. and its contributors.
|
||||
* 4. Neither the name of The NetBSD Foundation nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
|
||||
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
||||
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
|
||||
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
#include <sys/cdefs.h>
|
||||
__RCSID("$NetBSD: vsprintf_chk.c,v 1.1 2006/11/08 19:52:11 christos Exp $");
|
||||
|
||||
#include <ssp.h>
|
||||
#include <stdio.h>
|
||||
#include <limits.h>
|
||||
#include <stdarg.h>
|
||||
|
||||
/*ARGSUSED*/
|
||||
int
|
||||
__vsprintf_chk(char * __restrict buf, int flags, size_t slen,
|
||||
const char * __restrict fmt, va_list ap)
|
||||
{
|
||||
int rv;
|
||||
|
||||
if (slen > (size_t)INT_MAX)
|
||||
rv = vsprintf(buf, fmt, ap);
|
||||
else {
|
||||
if ((rv = vsnprintf(buf, slen, fmt, ap)) >= 0 && rv >= slen)
|
||||
__chk_fail();
|
||||
}
|
||||
|
||||
return rv;
|
||||
}
|
Loading…
Reference in New Issue
Block a user