Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 18 May 2024 18:42:39 +0000 (UTC)
From:      Pedro Giffuni <pfg@freebsd.org>
To:        "src-committers@freebsd.org" <src-committers@freebsd.org>,  "dev-commits-src-all@freebsd.org" <dev-commits-src-all@freebsd.org>,  "dev-commits-src-main@freebsd.org" <dev-commits-src-main@freebsd.org>,  Kyle Evans <kevans@freebsd.org>
Subject:   Re: git: be04fec42638 - main - Import _FORTIFY_SOURCE implementation from NetBSD
Message-ID:  <177052019.1587022.1716057759658@mail.yahoo.com>
In-Reply-To: <202405130524.44D5O9mN084277@gitrepo.freebsd.org>
References:  <202405130524.44D5O9mN084277@gitrepo.freebsd.org>

next in thread | previous in thread | raw e-mail | index | archive | help
------=_Part_1587021_1250298158.1716057759643
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

 Oh no .. please not...
We went into that in a GSoC:
https://wiki.freebsd.org/SummerOfCode2015/FreeBSDLibcSecurityExtensions


Ultimately it proved to be useless since stack-protector-strong.
The NetBSD code was not well adapted to clang either.
Ask me more if you really want to dig into it, but we don't want this.
Pedro.

    On Monday, May 13, 2024 at 12:24:13 AM GMT-5, Kyle Evans <kevans@freebs=
d.org> wrote: =20
=20
 The branch main has been updated by kevans:

URL: https://cgit.FreeBSD.org/src/commit/?id=3Dbe04fec42638f30f50b5b55fd8e3=
634c0fb89928

commit be04fec42638f30f50b5b55fd8e3634c0fb89928
Author:=C2=A0 =C2=A0 Kyle Evans <kevans@FreeBSD.org>
AuthorDate: 2024-05-13 05:23:49 +0000
Commit:=C2=A0 =C2=A0 Kyle Evans <kevans@FreeBSD.org>
CommitDate: 2024-05-13 05:23:49 +0000

=C2=A0 =C2=A0 Import _FORTIFY_SOURCE implementation from NetBSD
=C2=A0 =C2=A0=20
=C2=A0 =C2=A0 This is a mostly-unmodified copy of the various *_chk impleme=
ntations
=C2=A0 =C2=A0 and headers from NetBSD, without yet modifying system headers=
 to start
=C2=A0 =C2=A0 actually including them.=C2=A0 A future commit will also appl=
y the needed
=C2=A0 =C2=A0 bits to fix ssp/unistd.h.
=C2=A0 =C2=A0=20
=C2=A0 =C2=A0 Reviewed by:=C2=A0 =C2=A0 imp, pauamma_gundo.com (both previo=
us versions), kib
=C2=A0 =C2=A0 Sponsored by:=C2=A0 Stormshield
=C2=A0 =C2=A0 Sponsored by:=C2=A0 Klara, Inc.
=C2=A0 =C2=A0 Differential Revision:=C2=A0 https://reviews.freebsd.org/D323=
06
---
 etc/mtree/BSD.include.dist=C2=A0 =C2=A0 =C2=A0 =C2=A0 |=C2=A0 2 +
 include/Makefile=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =
=C2=A0 |=C2=A0 2 +-
 include/ssp/Makefile=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 |=C2=
=A0 6 ++
 include/ssp/ssp.h=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =
=C2=A0 |=C2=A0 91 ++++++++++++++++++++++++++
 include/ssp/stdio.h=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0=
 |=C2=A0 93 ++++++++++++++++++++++++++
 include/ssp/string.h=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 | 129=
 ++++++++++++++++++++++++++++++++++++
 include/ssp/strings.h=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 |=C2=
=A0 67 +++++++++++++++++++
 include/ssp/unistd.h=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 |=C2=
=A0 54 +++++++++++++++
 lib/libc/secure/Makefile.inc=C2=A0 =C2=A0 =C2=A0 |=C2=A0 11 ++++
 lib/libc/secure/Symbol.map=C2=A0 =C2=A0 =C2=A0 =C2=A0 |=C2=A0 18 +++++
 lib/libc/secure/fgets_chk.c=C2=A0 =C2=A0 =C2=A0 =C2=A0 |=C2=A0 54 ++++++++=
+++++++
 lib/libc/secure/gets_chk.c=C2=A0 =C2=A0 =C2=A0 =C2=A0 |=C2=A0 74 +++++++++=
++++++++++++
 lib/libc/secure/memcpy_chk.c=C2=A0 =C2=A0 =C2=A0 |=C2=A0 53 ++++++++++++++=
+
 lib/libc/secure/memmove_chk.c=C2=A0 =C2=A0 =C2=A0 |=C2=A0 47 +++++++++++++
 lib/libc/secure/memset_chk.c=C2=A0 =C2=A0 =C2=A0 |=C2=A0 46 +++++++++++++
 lib/libc/secure/snprintf_chk.c=C2=A0 =C2=A0 |=C2=A0 56 ++++++++++++++++
 lib/libc/secure/sprintf_chk.c=C2=A0 =C2=A0 =C2=A0 |=C2=A0 61 +++++++++++++=
++++
 lib/libc/secure/ssp_internal.h=C2=A0 =C2=A0 |=C2=A0 37 +++++++++++
 lib/libc/secure/stpcpy_chk.c=C2=A0 =C2=A0 =C2=A0 |=C2=A0 55 ++++++++++++++=
++
 lib/libc/secure/stpncpy_chk.c=C2=A0 =C2=A0 =C2=A0 |=C2=A0 53 +++++++++++++=
++
 lib/libc/secure/strcat_chk.c=C2=A0 =C2=A0 =C2=A0 |=C2=A0 60 ++++++++++++++=
+++
 lib/libc/secure/strcpy_chk.c=C2=A0 =C2=A0 =C2=A0 |=C2=A0 54 ++++++++++++++=
+
 lib/libc/secure/strncat_chk.c=C2=A0 =C2=A0 =C2=A0 |=C2=A0 70 +++++++++++++=
+++++++
 lib/libc/secure/strncpy_chk.c=C2=A0 =C2=A0 =C2=A0 |=C2=A0 53 +++++++++++++=
++
 lib/libc/secure/vsnprintf_chk.c=C2=A0 =C2=A0 |=C2=A0 49 ++++++++++++++
 lib/libc/secure/vsprintf_chk.c=C2=A0 =C2=A0 |=C2=A0 58 ++++++++++++++++
 lib/libssp/Makefile=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0=
 |=C2=A0 20 +++++-
 lib/libssp/Symbol.map=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 |=C2=
=A0 12 ++--
 lib/libssp/Versions.def=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 |=C2=A0 5=
 ++
 lib/libssp/__builtin_object_size.3 | 110 +++++++++++++++++++++++++++++++
 lib/libssp/fortify_stubs.c=C2=A0 =C2=A0 =C2=A0 =C2=A0 | 131 --------------=
-----------------------
 lib/libssp/ssp.3=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =
=C2=A0 | 130 ++++++++++++++++++++++++++++++++++++
 32 files changed, 1621 insertions(+), 140 deletions(-)

diff --git a/etc/mtree/BSD.include.dist b/etc/mtree/BSD.include.dist
index a6bd5880bf61..f8c83d6dde7a 100644
--- a/etc/mtree/BSD.include.dist
+++ b/etc/mtree/BSD.include.dist
@@ -372,6 +372,8 @@
=C2=A0 =C2=A0 =C2=A0 =C2=A0 mac_veriexec
=C2=A0 =C2=A0 =C2=A0 =C2=A0 ..
=C2=A0 =C2=A0 ..
+=C2=A0 =C2=A0 ssp
+=C2=A0 =C2=A0 ..
=C2=A0 =C2=A0 sys
=C2=A0 =C2=A0 =C2=A0 =C2=A0 disk
=C2=A0 =C2=A0 =C2=A0 =C2=A0 ..
diff --git a/include/Makefile b/include/Makefile
index 19e6beb95203..32774419f162 100644
--- a/include/Makefile
+++ b/include/Makefile
@@ -4,7 +4,7 @@
=20
 PACKAGE=3Dclibs
 CLEANFILES=3D osreldate.h version
-SUBDIR=3D arpa protocols rpcsvc rpc xlocale
+SUBDIR=3D arpa protocols rpcsvc rpc ssp xlocale
 .if ${MACHINE_CPUARCH} =3D=3D "amd64"
 SUBDIR+=3D=C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 i386
 INCLUDE_SUBDIRS+=3D=C2=A0=C2=A0=C2=A0 i386
diff --git a/include/ssp/Makefile b/include/ssp/Makefile
new file mode 100644
index 000000000000..dff19f43c920
--- /dev/null
+++ b/include/ssp/Makefile
@@ -0,0 +1,6 @@
+# $FreeBSD$
+
+INCS=3D=C2=A0=C2=A0=C2=A0 ssp.h stdio.h string.h strings.h unistd.h
+INCSDIR=3D=C2=A0=C2=A0=C2=A0 ${INCLUDEDIR}/ssp
+
+.include <bsd.prog.mk>
diff --git a/include/ssp/ssp.h b/include/ssp/ssp.h
new file mode 100644
index 000000000000..35a9aeee02df
--- /dev/null
+++ b/include/ssp/ssp.h
@@ -0,0 +1,91 @@
+/*=C2=A0=C2=A0=C2=A0 $NetBSD: ssp.h,v 1.13 2015/09/03 20:43:47 plunky Exp =
$=C2=A0=C2=A0=C2=A0 */
+
+/*-
+ *
+ * SPDX-License-Identifier: BSD-2-Clause
+ *
+ * Copyright (c) 2006, 2011 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
+ *=C2=A0 =C2=A0 notice, this list of conditions and the following disclaim=
er.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *=C2=A0 =C2=A0 notice, this list of conditions and the following disclaim=
er in the
+ *=C2=A0 =C2=A0 documentation and/or other materials provided with the dis=
tribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTO=
RS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIM=
ITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICU=
LAR
+ * PURPOSE ARE DISCLAIMED.=C2=A0 IN NO EVENT SHALL THE FOUNDATION OR CONTR=
IBUTORS
+ * 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 BUSINES=
S
+ * 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 defined(_FORTIFY_SOURCE) && _FORTIFY_SOURCE > 0 && \
+=C2=A0 =C2=A0 (__OPTIMIZE__ > 0 || defined(__clang__))
+#=C2=A0 if _FORTIFY_SOURCE > 1
+#=C2=A0 define __SSP_FORTIFY_LEVEL 2
+#=C2=A0 else
+#=C2=A0 define __SSP_FORTIFY_LEVEL 1
+#=C2=A0 endif
+# else
+#=C2=A0 define __SSP_FORTIFY_LEVEL 0
+# endif
+#else
+# define __SSP_FORTIFY_LEVEL 0
+#endif
+
+#define=C2=A0=C2=A0=C2=A0 __ssp_var(type)=C2=A0=C2=A0=C2=A0 __CONCAT(__ssp=
_ ## type, __COUNTER__)
+
+/* __ssp_real is used by the implementation in libc */
+#if __SSP_FORTIFY_LEVEL =3D=3D 0
+#define __ssp_real_(fun)=C2=A0=C2=A0=C2=A0 fun
+#else
+#define __ssp_real_(fun)=C2=A0=C2=A0=C2=A0 __ssp_real_ ## fun
+#endif
+#define __ssp_real(fun)=C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 __ssp_real_(f=
un)
+
+#define __ssp_inline static __inline __attribute__((__always_inline__))
+
+#define __ssp_bos(ptr) __builtin_object_size(ptr, __SSP_FORTIFY_LEVEL > 1)
+#define __ssp_bos0(ptr) __builtin_object_size(ptr, 0)
+
+#define __ssp_check(buf, len, bos) \
+=C2=A0=C2=A0=C2=A0 if (bos(buf) !=3D (size_t)-1 && len > bos(buf)) \
+=C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 __chk_fail()
+#define __ssp_redirect_raw(rtype, fun, symbol, args, call, cond, bos) \
+rtype __ssp_real_(fun) args __RENAME(symbol); \
+__ssp_inline rtype fun args __RENAME(__ssp_protected_ ## fun); \
+__ssp_inline rtype fun args { \
+=C2=A0=C2=A0=C2=A0 if (cond) \
+=C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 __ssp_check(__buf, __len, bos); \
+=C2=A0=C2=A0=C2=A0 return __ssp_real_(fun) call; \
+}
+
+#define __ssp_redirect(rtype, fun, args, call) \
+=C2=A0 =C2=A0 __ssp_redirect_raw(rtype, fun, fun, args, call, 1, __ssp_bos=
)
+#define __ssp_redirect0(rtype, fun, args, call) \
+=C2=A0 =C2=A0 __ssp_redirect_raw(rtype, fun, fun, args, call, 1, __ssp_bos=
0)
+
+__BEGIN_DECLS
+void __stack_chk_fail(void) __dead2;
+void __chk_fail(void) __dead2;
+__END_DECLS
+
+#endif /* _SSP_SSP_H_ */
diff --git a/include/ssp/stdio.h b/include/ssp/stdio.h
new file mode 100644
index 000000000000..72e3236eac80
--- /dev/null
+++ b/include/ssp/stdio.h
@@ -0,0 +1,93 @@
+/*=C2=A0=C2=A0=C2=A0 $NetBSD: stdio.h,v 1.5 2011/07/17 20:54:34 joerg Exp =
$=C2=A0=C2=A0=C2=A0 */
+
+/*-
+ *
+ * SPDX-License-Identifier: BSD-2-Clause
+ *
+ * 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
+ *=C2=A0 =C2=A0 notice, this list of conditions and the following disclaim=
er.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *=C2=A0 =C2=A0 notice, this list of conditions and the following disclaim=
er in the
+ *=C2=A0 =C2=A0 documentation and/or other materials provided with the dis=
tribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTO=
RS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIM=
ITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICU=
LAR
+ * PURPOSE ARE DISCLAIMED.=C2=A0 IN NO EVENT SHALL THE FOUNDATION OR CONTR=
IBUTORS
+ * 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 BUSINES=
S
+ * 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/ssp.h>
+
+__BEGIN_DECLS
+int __sprintf_chk(char *__restrict, int, size_t, const char *__restrict, .=
..)
+=C2=A0 =C2=A0 __printflike(4, 5);
+int __vsprintf_chk(char *__restrict, int, size_t, const char *__restrict,
+=C2=A0 =C2=A0 __va_list)
+=C2=A0 =C2=A0 __printflike(4, 0);
+int __snprintf_chk(char *__restrict, size_t, int, size_t,
+=C2=A0 =C2=A0 const char *__restrict, ...)
+=C2=A0 =C2=A0 __printflike(5, 6);
+int __vsnprintf_chk(char *__restrict, size_t, int, size_t,
+=C2=A0 =C2=A0 const char *__restrict, __va_list)
+=C2=A0 =C2=A0 __printflike(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, ...) ({=C2=A0=C2=A0=C2=A0 \
+=C2=A0 =C2=A0 char *_ssp_str =3D (str);=C2=A0=C2=A0=C2=A0 \
+=C2=A0 =C2=A0 __builtin___sprintf_chk(_ssp_str, 0, __ssp_bos(_ssp_str),=C2=
=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 \
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 __VA_ARGS__); \
+})
+
+#define vsprintf(str, fmt, ap) ({=C2=A0=C2=A0=C2=A0 \
+=C2=A0 =C2=A0 char *_ssp_str =3D (str);=C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=
=A0 \
+=C2=A0 =C2=A0 __builtin___vsprintf_chk(_ssp_str, 0, __ssp_bos(_ssp_str), f=
mt,=C2=A0=C2=A0=C2=A0 \
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 ap);=C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=
=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 \
+})
+
+#define snprintf(str, len, ...) ({=C2=A0=C2=A0=C2=A0 \
+=C2=A0 =C2=A0 char *_ssp_str =3D (str);=C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=
=A0 \
+=C2=A0 =C2=A0 __builtin___snprintf_chk(_ssp_str, len, 0, __ssp_bos(_ssp_st=
r),=C2=A0=C2=A0=C2=A0 \
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 __VA_ARGS__);=C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=
=C2=A0 =C2=A0=C2=A0=C2=A0 \
+})
+
+#define vsnprintf(str, len, fmt, ap) ({=C2=A0=C2=A0=C2=A0 \
+=C2=A0 =C2=A0 char *_ssp_str =3D (str);=C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=
=A0 \
+=C2=A0 =C2=A0 __builtin___vsnprintf_chk(_ssp_str, len, 0, __ssp_bos(_ssp_s=
tr),=C2=A0=C2=A0=C2=A0 \
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 fmt, ap);=C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0=
 =C2=A0=C2=A0=C2=A0 \
+})
+
+#define gets(str) ({=C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=
=A0 \
+=C2=A0 char *_ssp_str =3D (str);=C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 \
+=C2=A0 =C2=A0 __gets_chk(_ssp_str, __ssp_bos(_ssp_str));=C2=A0=C2=A0=C2=A0=
 \
+})
+
+#define fgets(str, len, fp) ({=C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 \
+=C2=A0 =C2=A0 char *_ssp_str =3D (str);=C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=
=A0 \
+=C2=A0 =C2=A0 __fgets_chk(_ssp_str, len, __ssp_bos(_ssp_str), fp);=C2=A0=
=C2=A0=C2=A0 \
+})
+
+#endif /* __SSP_FORTIFY_LEVEL > 0 */
+
+#endif /* _SSP_STDIO_H_ */
diff --git a/include/ssp/string.h b/include/ssp/string.h
new file mode 100644
index 000000000000..996020fda778
--- /dev/null
+++ b/include/ssp/string.h
@@ -0,0 +1,129 @@
+/*=C2=A0=C2=A0=C2=A0 $NetBSD: string.h,v 1.14 2020/09/05 13:37:59 mrg Exp =
$=C2=A0=C2=A0=C2=A0 */
+
+/*-
+ *
+ * SPDX-License-Identifier: BSD-2-Clause
+ *
+ * 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
+ *=C2=A0 =C2=A0 notice, this list of conditions and the following disclaim=
er.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *=C2=A0 =C2=A0 notice, this list of conditions and the following disclaim=
er in the
+ *=C2=A0 =C2=A0 documentation and/or other materials provided with the dis=
tribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTO=
RS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIM=
ITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICU=
LAR
+ * PURPOSE ARE DISCLAIMED.=C2=A0 IN NO EVENT SHALL THE FOUNDATION OR CONTR=
IBUTORS
+ * 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 BUSINES=
S
+ * 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/ssp.h>
+
+__BEGIN_DECLS
+void *__memcpy_chk(void *, const void *, size_t, size_t);
+void *__memmove_chk(void *, const void *, size_t, size_t);
+void *__memset_chk(void *, int, size_t, size_t);
+char *__stpcpy_chk(char *, const char *, size_t);
+char *__stpncpy_chk(char *, const char *, size_t, size_t);
+char *__strcat_chk(char *, const char *, size_t);
+char *__strcpy_chk(char *, const char *, size_t);
+char *__strncat_chk(char *, const char *, size_t, size_t);
+char *__strncpy_chk(char *, const char *, size_t, size_t);
+__END_DECLS
+
+#if __SSP_FORTIFY_LEVEL > 0
+
+#define __ssp_bos_check3_typed_var(fun, dsttype, dsrvar, dst, srctype, src=
var, \
+=C2=A0 =C2=A0 src, lenvar, len) ({=C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =
=C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 \
+=C2=A0 =C2=A0 srctype srcvar =3D (src);=C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=
=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 \
+=C2=A0 =C2=A0 dsttype dstvar =3D (dst);=C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=
=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 \
+=C2=A0 =C2=A0 size_t lenvar =3D (len);=C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=
=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 \
+=C2=A0 =C2=A0 ((__ssp_bos0(dstvar) !=3D (size_t)-1) ?=C2=A0=C2=A0=C2=A0 =
=C2=A0=C2=A0=C2=A0 \
+=C2=A0 =C2=A0 __builtin___ ## fun ## _chk(dstvar, srcvar, lenvar,=C2=A0=C2=
=A0=C2=A0 \
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 __ssp_bos0(dstvar)) :=C2=A0=C2=A0=C2=A0 =C2=A0=
=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 \
+=C2=A0 =C2=A0 __ ## fun ## _ichk(dstvar, srcvar, lenvar));=C2=A0=C2=A0=C2=
=A0 \
+})
+
+#define __ssp_bos_check3_typed(fun, dsttype, dst, srctype, src, len)=C2=A0=
=C2=A0=C2=A0 \
+=C2=A0 =C2=A0 __ssp_bos_check3_typed_var(fun, dsttype, __ssp_var(dstv), ds=
t,=C2=A0=C2=A0=C2=A0 \
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 srctype, __ssp_var(srcv), src, __ssp_var(lenv)=
, len)
+
+#define __ssp_bos_check3(fun, dst, src, len)=C2=A0=C2=A0=C2=A0 =C2=A0=C2=
=A0=C2=A0 \
+=C2=A0 =C2=A0 __ssp_bos_check3_typed_var(fun, void *, __ssp_var(dstv), dst=
,=C2=A0=C2=A0=C2=A0 \
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 const void *, __ssp_var(srcv), src, __ssp_var(=
lenv), len)
+
+#define __ssp_bos_check2_var(fun, dstvar, dst, srcvar, src) ({=C2=A0=C2=A0=
=C2=A0 =C2=A0=C2=A0=C2=A0 \
+=C2=A0 =C2=A0 const void *srcvar =3D (src);=C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=
=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 \
+=C2=A0 =C2=A0 void *dstvar =3D (dst);=C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0=
 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 \
+=C2=A0 =C2=A0 ((__ssp_bos0(dstvar) !=3D (size_t)-1) ?=C2=A0=C2=A0=C2=A0 =
=C2=A0=C2=A0=C2=A0 \
+=C2=A0 =C2=A0 __builtin___ ## fun ## _chk(dstvar, srcvar,=C2=A0=C2=A0=C2=
=A0 =C2=A0=C2=A0=C2=A0 \
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 __ssp_bos0(dstvar)) :=C2=A0=C2=A0=C2=A0 =C2=A0=
=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 \
+=C2=A0 =C2=A0 __ ## fun ## _ichk(dstvar, srcvar));=C2=A0=C2=A0=C2=A0 =C2=
=A0=C2=A0=C2=A0 \
+})
+
+#define __ssp_bos_check2(fun, dst, src)=C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=
=A0 =C2=A0=C2=A0=C2=A0 \
+=C2=A0 =C2=A0 __ssp_bos_check2_var(fun, __ssp_var(dstv), dst, __ssp_var(sr=
cv), src)
+
+#define __ssp_bos_icheck3_restrict(fun, type1, type2) \
+static __inline type1 __ ## fun ## _ichk(type1 __restrict, type2 __restric=
t, size_t); \
+static __inline __attribute__((__always_inline__)) type1 \
+__ ## fun ## _ichk(type1 __restrict dst, type2 __restrict src, size_t len)=
 { \
+=C2=A0=C2=A0=C2=A0 return __builtin___ ## fun ## _chk(dst, src, len, __ssp=
_bos0(dst)); \
+}
+
+#define __ssp_bos_icheck3(fun, type1, type2) \
+static __inline type1 __ ## fun ## _ichk(type1, type2, size_t); \
+static __inline __attribute__((__always_inline__)) type1 \
+__ ## fun ## _ichk(type1 dst, type2 src, size_t len) { \
+=C2=A0=C2=A0=C2=A0 return __builtin___ ## fun ## _chk(dst, src, len, __ssp=
_bos0(dst)); \
+}
+
+#define __ssp_bos_icheck2_restrict(fun, type1, type2) \
+static __inline type1 __ ## fun ## _ichk(type1, type2); \
+static __inline __attribute__((__always_inline__)) type1 \
+__ ## fun ## _ichk(type1 __restrict dst, type2 __restrict src) { \
+=C2=A0=C2=A0=C2=A0 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(stpcpy, char *, const char *)
+__ssp_bos_icheck3_restrict(stpncpy, char *, const char *)
+__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) \
+=C2=A0 =C2=A0 __ssp_bos_check3_typed(memset, void *, dst, int, val, len)
+#define stpcpy(dst, src) __ssp_bos_check2(stpcpy, dst, src)
+#define stpncpy(dst, src, len) __ssp_bos_check3(stpncpy, 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, len) __ssp_bos_check3(strncpy, dst, src, len)
+#define strncat(dst, src, len) __ssp_bos_check3(strncat, dst, src, len)
+
+#endif /* __SSP_FORTIFY_LEVEL > 0 */
+#endif /* _SSP_STRING_H_ */
diff --git a/include/ssp/strings.h b/include/ssp/strings.h
new file mode 100644
index 000000000000..06c9c7cc0a09
--- /dev/null
+++ b/include/ssp/strings.h
@@ -0,0 +1,67 @@
+/*=C2=A0=C2=A0=C2=A0 $NetBSD: strings.h,v 1.3 2008/04/28 20:22:54 martin E=
xp $=C2=A0=C2=A0=C2=A0 */
+
+/*-
+ *
+ * SPDX-License-Identifier: BSD-2-Clause
+ *
+ * Copyright (c) 2007 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
+ *=C2=A0 =C2=A0 notice, this list of conditions and the following disclaim=
er.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *=C2=A0 =C2=A0 notice, this list of conditions and the following disclaim=
er in the
+ *=C2=A0 =C2=A0 documentation and/or other materials provided with the dis=
tribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTO=
RS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIM=
ITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICU=
LAR
+ * PURPOSE ARE DISCLAIMED.=C2=A0 IN NO EVENT SHALL THE FOUNDATION OR CONTR=
IBUTORS
+ * 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 BUSINES=
S
+ * 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_STRINGS_H_
+#define _SSP_STRINGS_H_
+
+#include <ssp/ssp.h>
+#include <string.h>
+
+#if __SSP_FORTIFY_LEVEL > 0
+
+#define _ssp_bcopy(srcvar, src, dstvar, dst, lenvar,=C2=A0 len) ({=C2=A0=
=C2=A0=C2=A0 \
+=C2=A0 =C2=A0 const void *srcvar =3D (src);=C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=
=C2=A0 =C2=A0=C2=A0=C2=A0 \
+=C2=A0 =C2=A0 void *dstvar =3D (dst);=C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0=
 =C2=A0=C2=A0=C2=A0 \
+=C2=A0 =C2=A0 size_t lenvar =3D (len);=C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=
=A0 =C2=A0=C2=A0=C2=A0 \
+=C2=A0 =C2=A0 ((__ssp_bos0(dstvar) !=3D (size_t)-1) ?=C2=A0=C2=A0=C2=A0 \
+=C2=A0 =C2=A0 __builtin___memmove_chk(dstvar, srcvar, lenvar,=C2=A0=C2=A0=
=C2=A0 \
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 __ssp_bos0(dstvar)) :=C2=A0=C2=A0=C2=A0 =C2=A0=
=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 \
+=C2=A0 =C2=A0 __memmove_ichk(dstvar, srcvar, lenvar));=C2=A0=C2=A0=C2=A0 \
+})
+
+#define=C2=A0=C2=A0=C2=A0 bcopy(src, dst, len)=C2=A0=C2=A0=C2=A0 =C2=A0=C2=
=A0=C2=A0 =C2=A0=C2=A0=C2=A0 \
+=C2=A0 =C2=A0 _ssp_bcopy(__ssp_var(srcv), src, __ssp_var(dstv), dst, __ssp=
_var(lenv), len)
+
+#define _ssp_bzero(dstvar, dst, lenvar, len) ({=C2=A0=C2=A0=C2=A0 =C2=A0=
=C2=A0=C2=A0 \
+=C2=A0 =C2=A0 void *dstvar =3D (dst);=C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0=
 =C2=A0=C2=A0=C2=A0 \
+=C2=A0 =C2=A0 size_t lenvar =3D (len);=C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=
=A0 =C2=A0=C2=A0=C2=A0 \
+=C2=A0 =C2=A0 ((__ssp_bos0(dstvar) !=3D (size_t)-1) ?=C2=A0=C2=A0=C2=A0 \
+=C2=A0 =C2=A0 __builtin___memset_chk(dstvar, 0, lenvar,=C2=A0=C2=A0=C2=A0 =
\
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 __ssp_bos0(dstvar)) : \
+=C2=A0 =C2=A0 __memset_ichk(dstvar, 0, lenvar));=C2=A0=C2=A0=C2=A0 =C2=A0=
=C2=A0=C2=A0 \
+})
+
+#define=C2=A0=C2=A0=C2=A0 bzero(dst, len)=C2=A0=C2=A0=C2=A0 _ssp_bzero(__s=
sp_var(dstv), dst, __ssp_var(lenv), len)
+
+#endif /* __SSP_FORTIFY_LEVEL > 0 */
+#endif /* _SSP_STRINGS_H_ */
diff --git a/include/ssp/unistd.h b/include/ssp/unistd.h
new file mode 100644
index 000000000000..2414e2baa96b
--- /dev/null
+++ b/include/ssp/unistd.h
@@ -0,0 +1,54 @@
+/*=C2=A0=C2=A0=C2=A0 $NetBSD: unistd.h,v 1.7 2015/06/25 18:41:03 joerg Exp=
 $=C2=A0=C2=A0=C2=A0 */
+
+/*-
+ *
+ * SPDX-License-Identifier: BSD-2-Clause
+ *
+ * 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
+ *=C2=A0 =C2=A0 notice, this list of conditions and the following disclaim=
er.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *=C2=A0 =C2=A0 notice, this list of conditions and the following disclaim=
er in the
+ *=C2=A0 =C2=A0 documentation and/or other materials provided with the dis=
tribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTO=
RS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIM=
ITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICU=
LAR
+ * PURPOSE ARE DISCLAIMED.=C2=A0 IN NO EVENT SHALL THE FOUNDATION OR CONTR=
IBUTORS
+ * 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 BUSINES=
S
+ * 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/ssp.h>
+
+#if __SSP_FORTIFY_LEVEL > 0
+__BEGIN_DECLS
+
+__ssp_redirect0(ssize_t, read, (int __fd, void *__buf, size_t __len), \
+=C2=A0 =C2=A0 (__fd, __buf, __len));
+
+__ssp_redirect(ssize_t, readlink, (const char *__restrict __path, \
+=C2=A0 =C2=A0 char *__restrict __buf, size_t __len), (__path, __buf, __len=
));
+
+__ssp_redirect_raw(char *, getcwd, getcwd, (char *__buf, size_t __len),
+=C2=A0 =C2=A0 (__buf, __len), __buf !=3D 0, __ssp_bos);
+
+__END_DECLS
+
+#endif /* __SSP_FORTIFY_LEVEL > 0 */
+#endif /* _SSP_UNISTD_H_ */
diff --git a/lib/libc/secure/Makefile.inc b/lib/libc/secure/Makefile.inc
index 8574c5a05dc5..3b1ad879c715 100644
--- a/lib/libc/secure/Makefile.inc
+++ b/lib/libc/secure/Makefile.inc
@@ -3,6 +3,17 @@
=20
 .PATH: ${LIBC_SRCTOP}/secure
=20
+# _FORTIFY_SOURCE
+SRCS+=3D=C2=A0=C2=A0=C2=A0 gets_chk.c fgets_chk.c memcpy_chk.c memmove_chk=
.c memset_chk.c \
+=C2=A0=C2=A0=C2=A0 snprintf_chk.c sprintf_chk.c stpcpy_chk.c stpncpy_chk.c=
 \
+=C2=A0=C2=A0=C2=A0 strcat_chk.c strcpy_chk.c strncat_chk.c strncpy_chk.c \
+=C2=A0=C2=A0=C2=A0 vsnprintf_chk.c vsprintf_chk.c
+
+CFLAGS.snprintf_chk.c+=3D=C2=A0=C2=A0=C2=A0 -Wno-unused-parameter
+CFLAGS.sprintf_chk.c+=3D=C2=A0=C2=A0=C2=A0 -Wno-unused-parameter
+CFLAGS.vsnprintf_chk.c+=3D=C2=A0=C2=A0=C2=A0 -Wno-unused-parameter
+CFLAGS.vsprintf_chk.c+=3D=C2=A0=C2=A0=C2=A0 -Wno-unused-parameter
+
 # Sources common to both syscall interfaces:
 SRCS+=3D=C2=A0=C2=A0=C2=A0 stack_protector.c \
 =C2=A0=C2=A0=C2=A0 stack_protector_compat.c
diff --git a/lib/libc/secure/Symbol.map b/lib/libc/secure/Symbol.map
index 641f451b5421..7859fcee3821 100644
--- a/lib/libc/secure/Symbol.map
+++ b/lib/libc/secure/Symbol.map
@@ -3,3 +3,21 @@ FBSD_1.0 {
 =C2=A0=C2=A0=C2=A0 __stack_chk_fail;
 =C2=A0=C2=A0=C2=A0 __stack_chk_guard;
 };
+
+FBSD_1.8 {
+=C2=A0=C2=A0=C2=A0 __gets_chk;
+=C2=A0=C2=A0=C2=A0 __fgets_chk;
+=C2=A0=C2=A0=C2=A0 __memcpy_chk;
+=C2=A0=C2=A0=C2=A0 __memmove_chk;
+=C2=A0=C2=A0=C2=A0 __memset_chk;
+=C2=A0=C2=A0=C2=A0 __snprintf_chk;
+=C2=A0=C2=A0=C2=A0 __sprintf_chk;
+=C2=A0=C2=A0=C2=A0 __stpcpy_chk;
+=C2=A0=C2=A0=C2=A0 __stpncpy_chk;
+=C2=A0=C2=A0=C2=A0 __strcat_chk;
+=C2=A0=C2=A0=C2=A0 __strcpy_chk;
+=C2=A0=C2=A0=C2=A0 __strncat_chk;
+=C2=A0=C2=A0=C2=A0 __strncpy_chk;
+=C2=A0=C2=A0=C2=A0 __vsnprintf_chk;
+=C2=A0=C2=A0=C2=A0 __vsprintf_chk;
+};
diff --git a/lib/libc/secure/fgets_chk.c b/lib/libc/secure/fgets_chk.c
new file mode 100644
index 000000000000..72aa1d816ce1
--- /dev/null
+++ b/lib/libc/secure/fgets_chk.c
@@ -0,0 +1,54 @@
+/*-
+ *
+ * SPDX-License-Identifier: BSD-2-Clause
+ *
+ * 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
+ *=C2=A0 =C2=A0 notice, this list of conditions and the following disclaim=
er.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *=C2=A0 =C2=A0 notice, this list of conditions and the following disclaim=
er in the
+ *=C2=A0 =C2=A0 documentation and/or other materials provided with the dis=
tribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTO=
RS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIM=
ITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICU=
LAR
+ * PURPOSE ARE DISCLAIMED.=C2=A0 IN NO EVENT SHALL THE FOUNDATION OR CONTR=
IBUTORS
+ * 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 BUSINES=
S
+ * 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.6 2009/02/05 05:41:51 lukem Exp $");
+
+#include <limits.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include <ssp/stdio.h>
+#include <ssp/string.h>
+#undef fgets
+
+char *
+__fgets_chk(char * __restrict buf, int len, size_t slen, FILE *fp)
+{
+=C2=A0=C2=A0=C2=A0 if (slen >=3D (size_t)INT_MAX)
+=C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 return (fgets(buf, len, fp));
+
+=C2=A0=C2=A0=C2=A0 if (len >=3D 0 && (size_t)len > slen)
+=C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 __chk_fail();
+
+=C2=A0=C2=A0=C2=A0 return (fgets(buf, len, fp));
+}
diff --git a/lib/libc/secure/gets_chk.c b/lib/libc/secure/gets_chk.c
new file mode 100644
index 000000000000..18c1e2d18f43
--- /dev/null
+++ b/lib/libc/secure/gets_chk.c
@@ -0,0 +1,74 @@
+/*-
+ *
+ * SPDX-License-Identifier: BSD-2-Clause
+ *
+ * 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
+ *=C2=A0 =C2=A0 notice, this list of conditions and the following disclaim=
er.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *=C2=A0 =C2=A0 notice, this list of conditions and the following disclaim=
er in the
+ *=C2=A0 =C2=A0 documentation and/or other materials provided with the dis=
tribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTO=
RS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIM=
ITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICU=
LAR
+ * PURPOSE ARE DISCLAIMED.=C2=A0 IN NO EVENT SHALL THE FOUNDATION OR CONTR=
IBUTORS
+ * 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 BUSINES=
S
+ * 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.7 2013/10/04 20:49:16 christos Exp $");
+
+#include <limits.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include <ssp/stdio.h>
+#include <ssp/string.h>
+
+char *__gets_unsafe(char *);
+
+char *
+__gets_chk(char * __restrict buf, size_t slen)
+{
+=C2=A0=C2=A0=C2=A0 char *abuf;
+=C2=A0=C2=A0=C2=A0 size_t len;
+
+=C2=A0=C2=A0=C2=A0 if (slen >=3D (size_t)INT_MAX)
+=C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 return (__gets_unsafe(buf));
+
+=C2=A0=C2=A0=C2=A0 if ((abuf =3D malloc(slen + 1)) =3D=3D NULL)
+=C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 return (__gets_unsafe(buf));
+
+=C2=A0=C2=A0=C2=A0 if (fgets(abuf, (int)(slen + 1), stdin) =3D=3D NULL) {
+=C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 free(abuf);
+=C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 return (NULL);
+=C2=A0=C2=A0=C2=A0 }
+
+=C2=A0=C2=A0=C2=A0 len =3D strlen(abuf);
+=C2=A0=C2=A0=C2=A0 if (len > 0 && abuf[len - 1] =3D=3D '\n')
+=C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 --len;
+
+=C2=A0=C2=A0=C2=A0 if (len >=3D slen)
+=C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 __chk_fail();
+
+=C2=A0=C2=A0=C2=A0 (void)memcpy(buf, abuf, len);
+
+=C2=A0=C2=A0=C2=A0 buf[len] =3D '\0';
+=C2=A0=C2=A0=C2=A0 free(abuf);
+=C2=A0=C2=A0=C2=A0 return (buf);
+}
diff --git a/lib/libc/secure/memcpy_chk.c b/lib/libc/secure/memcpy_chk.c
new file mode 100644
index 000000000000..99cf2d5f13ff
--- /dev/null
+++ b/lib/libc/secure/memcpy_chk.c
@@ -0,0 +1,53 @@
+/*-
+ *
+ * SPDX-License-Identifier: BSD-2-Clause
+ *
+ * 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
+ *=C2=A0 =C2=A0 notice, this list of conditions and the following disclaim=
er.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *=C2=A0 =C2=A0 notice, this list of conditions and the following disclaim=
er in the
+ *=C2=A0 =C2=A0 documentation and/or other materials provided with the dis=
tribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTO=
RS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIM=
ITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICU=
LAR
+ * PURPOSE ARE DISCLAIMED.=C2=A0 IN NO EVENT SHALL THE FOUNDATION OR CONTR=
IBUTORS
+ * 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 BUSINES=
S
+ * 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.7 2015/05/13 19:57:16 joerg Exp $");
+
+#include <string.h>
+
+#include <ssp/string.h>
+#undef memcpy
+
+#include "ssp_internal.h"
+
+void *
+__memcpy_chk(void * __restrict dst, const void * __restrict src, size_t le=
n,
+=C2=A0 =C2=A0 size_t slen)
+{
+=C2=A0=C2=A0=C2=A0 if (len > slen)
+=C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 __chk_fail();
+
+=C2=A0=C2=A0=C2=A0 if (__ssp_overlap((const char *)src, (const char *)dst,=
 len))
+=C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 __chk_fail();
+
+=C2=A0=C2=A0=C2=A0 return (memcpy(dst, src, len));
+}
diff --git a/lib/libc/secure/memmove_chk.c b/lib/libc/secure/memmove_chk.c
new file mode 100644
index 000000000000..07f965d608fc
--- /dev/null
+++ b/lib/libc/secure/memmove_chk.c
@@ -0,0 +1,47 @@
+/*-
+ *
+ * SPDX-License-Identifier: BSD-2-Clause
+ *
+ * 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
+ *=C2=A0 =C2=A0 notice, this list of conditions and the following disclaim=
er.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *=C2=A0 =C2=A0 notice, this list of conditions and the following disclaim=
er in the
+ *=C2=A0 =C2=A0 documentation and/or other materials provided with the dis=
tribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTO=
RS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIM=
ITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICU=
LAR
+ * PURPOSE ARE DISCLAIMED.=C2=A0 IN NO EVENT SHALL THE FOUNDATION OR CONTR=
IBUTORS
+ * 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 BUSINES=
S
+ * 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.6 2020/09/05 13:37:59 mrg Exp $");
+
+#include <string.h>
+
+#include <ssp/string.h>
+#undef memmove
+
+void *
+__memmove_chk(void *dst, const void *src, size_t len,
+=C2=A0 =C2=A0 size_t slen)
+{
+=C2=A0=C2=A0=C2=A0 if (len > slen)
+=C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 __chk_fail();
+=C2=A0=C2=A0=C2=A0 return (memmove(dst, src, len));
+}
diff --git a/lib/libc/secure/memset_chk.c b/lib/libc/secure/memset_chk.c
new file mode 100644
index 000000000000..f337be98b46d
--- /dev/null
+++ b/lib/libc/secure/memset_chk.c
@@ -0,0 +1,46 @@
+/*-
+ *
+ * SPDX-License-Identifier: BSD-2-Clause
+ *
+ * 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
+ *=C2=A0 =C2=A0 notice, this list of conditions and the following disclaim=
er.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *=C2=A0 =C2=A0 notice, this list of conditions and the following disclaim=
er in the
+ *=C2=A0 =C2=A0 documentation and/or other materials provided with the dis=
tribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTO=
RS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIM=
ITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICU=
LAR
+ * PURPOSE ARE DISCLAIMED.=C2=A0 IN NO EVENT SHALL THE FOUNDATION OR CONTR=
IBUTORS
+ * 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 BUSINES=
S
+ * 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.5 2014/09/17 00:39:28 joerg Exp $");
+
+#include <string.h>
+
+#include <ssp/string.h>
+#undef memset
+
+void *
+__memset_chk(void * __restrict dst, int val, size_t len, size_t slen)
+{
+=C2=A0=C2=A0=C2=A0 if (len > slen)
+=C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 __chk_fail();
+=C2=A0=C2=A0=C2=A0 return (memset(dst, val, len));
+}
diff --git a/lib/libc/secure/snprintf_chk.c b/lib/libc/secure/snprintf_chk.=
c
new file mode 100644
index 000000000000..52ef874ede5b
--- /dev/null
+++ b/lib/libc/secure/snprintf_chk.c
@@ -0,0 +1,56 @@
+/*-
+ *
+ * SPDX-License-Identifier: BSD-2-Clause
+ *
+ * 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
+ *=C2=A0 =C2=A0 notice, this list of conditions and the following disclaim=
er.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *=C2=A0 =C2=A0 notice, this list of conditions and the following disclaim=
er in the
+ *=C2=A0 =C2=A0 documentation and/or other materials provided with the dis=
tribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTO=
RS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIM=
ITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICU=
LAR
+ * PURPOSE ARE DISCLAIMED.=C2=A0 IN NO EVENT SHALL THE FOUNDATION OR CONTR=
IBUTORS
+ * 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 BUSINES=
S
+ * 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.5 2008/04/28 20:23:00 martin Exp $");
+
+#include <stdarg.h>
+#include <stdio.h>
+
+#include <ssp/stdio.h>
+#undef vsnprintf
+
+int
+__snprintf_chk(char * __restrict buf, size_t len, int flags, size_t slen,
+=C2=A0 =C2=A0 const char * __restrict fmt, ...)
+{
+=C2=A0=C2=A0=C2=A0 va_list ap;
+=C2=A0=C2=A0=C2=A0 int rv;
+
+=C2=A0=C2=A0=C2=A0 if (len > slen)
+=C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 __chk_fail();
+
+=C2=A0=C2=A0=C2=A0 va_start(ap, fmt);
+=C2=A0=C2=A0=C2=A0 rv =3D vsnprintf(buf, len, fmt, ap);
+=C2=A0=C2=A0=C2=A0 va_end(ap);
+
+=C2=A0=C2=A0=C2=A0 return (rv);
+}
diff --git a/lib/libc/secure/sprintf_chk.c b/lib/libc/secure/sprintf_chk.c
new file mode 100644
index 000000000000..d4c42ccba3ce
--- /dev/null
+++ b/lib/libc/secure/sprintf_chk.c
@@ -0,0 +1,61 @@
+/*-
+ *
+ * SPDX-License-Identifier: BSD-2-Clause
+ *
+ * Copyright (c) 2006 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
*** 1063 LINES SKIPPED ***
 =20
------=_Part_1587021_1250298158.1716057759643
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

<html><head></head><body><div class=3D"ydp2680af1fyahoo-style-wrap" style=
=3D"font-family:Helvetica Neue, Helvetica, Arial, sans-serif;font-size:16px=
;"><div></div>
        <div dir=3D"ltr" data-setdir=3D"false">Oh no .. please not...</div>=
<div dir=3D"ltr" data-setdir=3D"false"><br></div><div dir=3D"ltr" data-setd=
ir=3D"false">We went into that in a GSoC:</div><div dir=3D"ltr" data-setdir=
=3D"false"><br></div><div dir=3D"ltr" data-setdir=3D"false"><a href=3D"http=
s://wiki.freebsd.org/SummerOfCode2015/FreeBSDLibcSecurityExtensions" rel=3D=
"nofollow" target=3D"_blank" class=3D"">https://wiki.freebsd.org/SummerOfCo=
de2015/FreeBSDLibcSecurityExtensions</a><br></div><div><br></div><div><br><=
/div><div dir=3D"ltr" data-setdir=3D"false">Ultimately it proved to be usel=
ess since stack-protector-strong.</div><div dir=3D"ltr" data-setdir=3D"fals=
e"><br></div><div dir=3D"ltr" data-setdir=3D"false">The NetBSD code was not=
 well adapted to clang either.</div><div dir=3D"ltr" data-setdir=3D"false">=
<br></div><div dir=3D"ltr" data-setdir=3D"false">Ask me more if you really =
want to dig into it, but we don't want this.</div><div dir=3D"ltr" data-set=
dir=3D"false"><br></div><div dir=3D"ltr" data-setdir=3D"false">Pedro.</div>=
<div><br></div><div><br></div>
       =20
        </div><div id=3D"ydpa32aaebeyahoo_quoted_6496172397" class=3D"ydpa3=
2aaebeyahoo_quoted">
            <div style=3D"font-family:'Helvetica Neue', Helvetica, Arial, s=
ans-serif;font-size:13px;color:#26282a;">
               =20
                <div>
                        On Monday, May 13, 2024 at 12:24:13 AM GMT-5, Kyle =
Evans &lt;kevans@freebsd.org&gt; wrote:
                    </div>
                    <div><br></div>
                    <div><br></div>
               =20
               =20
                <div><div dir=3D"ltr">The branch main has been updated by k=
evans:<br></div><div dir=3D"ltr"><br></div><div dir=3D"ltr">URL: <a href=3D=
"https://cgit.FreeBSD.org/src/commit/?id=3Dbe04fec42638f30f50b5b55fd8e3634c=
0fb89928" rel=3D"nofollow" target=3D"_blank">https://cgit.FreeBSD.org/src/c=
ommit/?id=3Dbe04fec42638f30f50b5b55fd8e3634c0fb89928</a><br></div><div dir=
=3D"ltr"><br></div><div dir=3D"ltr">commit be04fec42638f30f50b5b55fd8e3634c=
0fb89928<br></div><div dir=3D"ltr">Author:&nbsp; &nbsp;  Kyle Evans &lt;<a =
href=3D"mailto:kevans@FreeBSD.org" rel=3D"nofollow" target=3D"_blank">kevan=
s@FreeBSD.org</a>&gt;<br></div><div dir=3D"ltr">AuthorDate: 2024-05-13 05:2=
3:49 +0000<br></div><div dir=3D"ltr">Commit:&nbsp; &nbsp;  Kyle Evans &lt;<=
a href=3D"mailto:kevans@FreeBSD.org" rel=3D"nofollow" target=3D"_blank">kev=
ans@FreeBSD.org</a>&gt;<br></div><div dir=3D"ltr">CommitDate: 2024-05-13 05=
:23:49 +0000<br></div><div dir=3D"ltr"><br></div><div dir=3D"ltr">&nbsp; &n=
bsp; Import _FORTIFY_SOURCE implementation from NetBSD<br></div><div dir=3D=
"ltr">&nbsp; &nbsp; <br></div><div dir=3D"ltr">&nbsp; &nbsp; This is a most=
ly-unmodified copy of the various *_chk implementations<br></div><div dir=
=3D"ltr">&nbsp; &nbsp; and headers from NetBSD, without yet modifying syste=
m headers to start<br></div><div dir=3D"ltr">&nbsp; &nbsp; actually includi=
ng them.&nbsp; A future commit will also apply the needed<br></div><div dir=
=3D"ltr">&nbsp; &nbsp; bits to fix ssp/unistd.h.<br></div><div dir=3D"ltr">=
&nbsp; &nbsp; <br></div><div dir=3D"ltr">&nbsp; &nbsp; Reviewed by:&nbsp; &=
nbsp; imp, pauamma_gundo.com (both previous versions), kib<br></div><div di=
r=3D"ltr">&nbsp; &nbsp; Sponsored by:&nbsp;  Stormshield<br></div><div dir=
=3D"ltr">&nbsp; &nbsp; Sponsored by:&nbsp;  Klara, Inc.<br></div><div dir=
=3D"ltr">&nbsp; &nbsp; Differential Revision:&nbsp; <a href=3D"https://revi=
ews.freebsd.org/D32306" rel=3D"nofollow" target=3D"_blank">https://reviews.=
freebsd.org/D32306</a><br></div><div dir=3D"ltr">---<br></div><div dir=3D"l=
tr"> etc/mtree/BSD.include.dist&nbsp; &nbsp; &nbsp; &nbsp;  |&nbsp;  2 +<br=
></div><div dir=3D"ltr"> include/Makefile&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;=
 &nbsp; &nbsp; &nbsp; &nbsp;  |&nbsp;  2 +-<br></div><div dir=3D"ltr"> incl=
ude/ssp/Makefile&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  |&nbsp;  =
6 ++<br></div><div dir=3D"ltr"> include/ssp/ssp.h&nbsp; &nbsp; &nbsp; &nbsp=
; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; |&nbsp; 91 ++++++++++++++++++++++++++<=
br></div><div dir=3D"ltr"> include/ssp/stdio.h&nbsp; &nbsp; &nbsp; &nbsp; &=
nbsp; &nbsp; &nbsp; &nbsp; |&nbsp; 93 ++++++++++++++++++++++++++<br></div><=
div dir=3D"ltr"> include/ssp/string.h&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nb=
sp; &nbsp;  | 129 ++++++++++++++++++++++++++++++++++++<br></div><div dir=3D=
"ltr"> include/ssp/strings.h&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp=
; |&nbsp; 67 +++++++++++++++++++<br></div><div dir=3D"ltr"> include/ssp/uni=
std.h&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  |&nbsp; 54 +++++++++=
++++++<br></div><div dir=3D"ltr"> lib/libc/secure/Makefile.inc&nbsp; &nbsp;=
 &nbsp;  |&nbsp; 11 ++++<br></div><div dir=3D"ltr"> lib/libc/secure/Symbol.=
map&nbsp; &nbsp; &nbsp; &nbsp;  |&nbsp; 18 +++++<br></div><div dir=3D"ltr">=
 lib/libc/secure/fgets_chk.c&nbsp; &nbsp; &nbsp; &nbsp; |&nbsp; 54 ++++++++=
+++++++<br></div><div dir=3D"ltr"> lib/libc/secure/gets_chk.c&nbsp; &nbsp; =
&nbsp; &nbsp;  |&nbsp; 74 +++++++++++++++++++++<br></div><div dir=3D"ltr"> =
lib/libc/secure/memcpy_chk.c&nbsp; &nbsp; &nbsp;  |&nbsp; 53 ++++++++++++++=
+<br></div><div dir=3D"ltr"> lib/libc/secure/memmove_chk.c&nbsp; &nbsp; &nb=
sp; |&nbsp; 47 +++++++++++++<br></div><div dir=3D"ltr"> lib/libc/secure/mem=
set_chk.c&nbsp; &nbsp; &nbsp;  |&nbsp; 46 +++++++++++++<br></div><div dir=
=3D"ltr"> lib/libc/secure/snprintf_chk.c&nbsp; &nbsp;  |&nbsp; 56 +++++++++=
+++++++<br></div><div dir=3D"ltr"> lib/libc/secure/sprintf_chk.c&nbsp; &nbs=
p; &nbsp; |&nbsp; 61 +++++++++++++++++<br></div><div dir=3D"ltr"> lib/libc/=
secure/ssp_internal.h&nbsp; &nbsp;  |&nbsp; 37 +++++++++++<br></div><div di=
r=3D"ltr"> lib/libc/secure/stpcpy_chk.c&nbsp; &nbsp; &nbsp;  |&nbsp; 55 +++=
+++++++++++++<br></div><div dir=3D"ltr"> lib/libc/secure/stpncpy_chk.c&nbsp=
; &nbsp; &nbsp; |&nbsp; 53 +++++++++++++++<br></div><div dir=3D"ltr"> lib/l=
ibc/secure/strcat_chk.c&nbsp; &nbsp; &nbsp;  |&nbsp; 60 +++++++++++++++++<b=
r></div><div dir=3D"ltr"> lib/libc/secure/strcpy_chk.c&nbsp; &nbsp; &nbsp; =
 |&nbsp; 54 +++++++++++++++<br></div><div dir=3D"ltr"> lib/libc/secure/strn=
cat_chk.c&nbsp; &nbsp; &nbsp; |&nbsp; 70 ++++++++++++++++++++<br></div><div=
 dir=3D"ltr"> lib/libc/secure/strncpy_chk.c&nbsp; &nbsp; &nbsp; |&nbsp; 53 =
+++++++++++++++<br></div><div dir=3D"ltr"> lib/libc/secure/vsnprintf_chk.c&=
nbsp; &nbsp; |&nbsp; 49 ++++++++++++++<br></div><div dir=3D"ltr"> lib/libc/=
secure/vsprintf_chk.c&nbsp; &nbsp;  |&nbsp; 58 ++++++++++++++++<br></div><d=
iv dir=3D"ltr"> lib/libssp/Makefile&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp=
; &nbsp; &nbsp; |&nbsp; 20 +++++-<br></div><div dir=3D"ltr"> lib/libssp/Sym=
bol.map&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; |&nbsp; 12 ++--<br>=
</div><div dir=3D"ltr"> lib/libssp/Versions.def&nbsp; &nbsp; &nbsp; &nbsp; =
&nbsp; &nbsp; |&nbsp;  5 ++<br></div><div dir=3D"ltr"> lib/libssp/__builtin=
_object_size.3 | 110 +++++++++++++++++++++++++++++++<br></div><div dir=3D"l=
tr"> lib/libssp/fortify_stubs.c&nbsp; &nbsp; &nbsp; &nbsp;  | 131 ---------=
----------------------------<br></div><div dir=3D"ltr"> lib/libssp/ssp.3&nb=
sp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  | 130 ++++++++=
++++++++++++++++++++++++++++<br></div><div dir=3D"ltr"> 32 files changed, 1=
621 insertions(+), 140 deletions(-)<br></div><div dir=3D"ltr"><br></div><di=
v dir=3D"ltr">diff --git a/etc/mtree/BSD.include.dist b/etc/mtree/BSD.inclu=
de.dist<br></div><div dir=3D"ltr">index a6bd5880bf61..f8c83d6dde7a 100644<b=
r></div><div dir=3D"ltr">--- a/etc/mtree/BSD.include.dist<br></div><div dir=
=3D"ltr">+++ b/etc/mtree/BSD.include.dist<br></div><div dir=3D"ltr">@@ -372=
,6 +372,8 @@<br></div><div dir=3D"ltr">&nbsp; &nbsp; &nbsp; &nbsp;  mac_ver=
iexec<br></div><div dir=3D"ltr">&nbsp; &nbsp; &nbsp; &nbsp;  ..<br></div><d=
iv dir=3D"ltr">&nbsp; &nbsp;  ..<br></div><div dir=3D"ltr">+&nbsp; &nbsp; s=
sp<br></div><div dir=3D"ltr">+&nbsp; &nbsp; ..<br></div><div dir=3D"ltr">&n=
bsp; &nbsp;  sys<br></div><div dir=3D"ltr">&nbsp; &nbsp; &nbsp; &nbsp;  dis=
k<br></div><div dir=3D"ltr">&nbsp; &nbsp; &nbsp; &nbsp;  ..<br></div><div d=
ir=3D"ltr">diff --git a/include/Makefile b/include/Makefile<br></div><div d=
ir=3D"ltr">index 19e6beb95203..32774419f162 100644<br></div><div dir=3D"ltr=
">--- a/include/Makefile<br></div><div dir=3D"ltr">+++ b/include/Makefile<b=
r></div><div dir=3D"ltr">@@ -4,7 +4,7 @@<br></div><div dir=3D"ltr"> <br></d=
iv><div dir=3D"ltr"> PACKAGE=3Dclibs<br></div><div dir=3D"ltr"> CLEANFILES=
=3D osreldate.h version<br></div><div dir=3D"ltr">-SUBDIR=3D arpa protocols=
 rpcsvc rpc xlocale<br></div><div dir=3D"ltr">+SUBDIR=3D arpa protocols rpc=
svc rpc ssp xlocale<br></div><div dir=3D"ltr"> .if ${MACHINE_CPUARCH} =3D=
=3D "amd64"<br></div><div dir=3D"ltr"> SUBDIR+=3D&nbsp;&nbsp;&nbsp; &nbsp;&=
nbsp;&nbsp; i386<br></div><div dir=3D"ltr"> INCLUDE_SUBDIRS+=3D&nbsp;&nbsp;=
&nbsp; i386<br></div><div dir=3D"ltr">diff --git a/include/ssp/Makefile b/i=
nclude/ssp/Makefile<br></div><div dir=3D"ltr">new file mode 100644<br></div=
><div dir=3D"ltr">index 000000000000..dff19f43c920<br></div><div dir=3D"ltr=
">--- /dev/null<br></div><div dir=3D"ltr">+++ b/include/ssp/Makefile<br></d=
iv><div dir=3D"ltr">@@ -0,0 +1,6 @@<br></div><div dir=3D"ltr">+# $FreeBSD$<=
br></div><div dir=3D"ltr">+<br></div><div dir=3D"ltr">+INCS=3D&nbsp;&nbsp;&=
nbsp; ssp.h stdio.h string.h strings.h unistd.h<br></div><div dir=3D"ltr">+=
INCSDIR=3D&nbsp;&nbsp;&nbsp; ${INCLUDEDIR}/ssp<br></div><div dir=3D"ltr">+<=
br></div><div dir=3D"ltr">+.include &lt;bsd.prog.mk&gt;<br></div><div dir=
=3D"ltr">diff --git a/include/ssp/ssp.h b/include/ssp/ssp.h<br></div><div d=
ir=3D"ltr">new file mode 100644<br></div><div dir=3D"ltr">index 00000000000=
0..35a9aeee02df<br></div><div dir=3D"ltr">--- /dev/null<br></div><div dir=
=3D"ltr">+++ b/include/ssp/ssp.h<br></div><div dir=3D"ltr">@@ -0,0 +1,91 @@=
<br></div><div dir=3D"ltr">+/*&nbsp;&nbsp;&nbsp; $NetBSD: ssp.h,v 1.13 2015=
/09/03 20:43:47 plunky Exp $&nbsp;&nbsp;&nbsp; */<br></div><div dir=3D"ltr"=
>+<br></div><div dir=3D"ltr">+/*-<br></div><div dir=3D"ltr">+ *<br></div><d=
iv dir=3D"ltr">+ * SPDX-License-Identifier: BSD-2-Clause<br></div><div dir=
=3D"ltr">+ *<br></div><div dir=3D"ltr">+ * Copyright (c) 2006, 2011 The Net=
BSD Foundation, Inc.<br></div><div dir=3D"ltr">+ * All rights reserved.<br>=
</div><div dir=3D"ltr">+ *<br></div><div dir=3D"ltr">+ * This code is deriv=
ed from software contributed to The NetBSD Foundation<br></div><div dir=3D"=
ltr">+ * by Christos Zoulas.<br></div><div dir=3D"ltr">+ *<br></div><div di=
r=3D"ltr">+ * Redistribution and use in source and binary forms, with or wi=
thout<br></div><div dir=3D"ltr">+ * modification, are permitted provided th=
at the following conditions<br></div><div dir=3D"ltr">+ * are met:<br></div=
><div dir=3D"ltr">+ * 1. Redistributions of source code must retain the abo=
ve copyright<br></div><div dir=3D"ltr">+ *&nbsp; &nbsp; notice, this list o=
f conditions and the following disclaimer.<br></div><div dir=3D"ltr">+ * 2.=
 Redistributions in binary form must reproduce the above copyright<br></div=
><div dir=3D"ltr">+ *&nbsp; &nbsp; notice, this list of conditions and the =
following disclaimer in the<br></div><div dir=3D"ltr">+ *&nbsp; &nbsp; docu=
mentation and/or other materials provided with the distribution.<br></div><=
div dir=3D"ltr">+ *<br></div><div dir=3D"ltr">+ * THIS SOFTWARE IS PROVIDED=
 BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS<br></div><div dir=3D"ltr">=
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIM=
ITED<br></div><div dir=3D"ltr">+ * TO, THE IMPLIED WARRANTIES OF MERCHANTAB=
ILITY AND FITNESS FOR A PARTICULAR<br></div><div dir=3D"ltr">+ * PURPOSE AR=
E DISCLAIMED.&nbsp; IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS<br></d=
iv><div dir=3D"ltr">+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPE=
CIAL, EXEMPLARY, OR<br></div><div dir=3D"ltr">+ * CONSEQUENTIAL DAMAGES (IN=
CLUDING, BUT NOT LIMITED TO, PROCUREMENT OF<br></div><div dir=3D"ltr">+ * S=
UBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS<br>=
</div><div dir=3D"ltr">+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY O=
F LIABILITY, WHETHER IN<br></div><div dir=3D"ltr">+ * CONTRACT, STRICT LIAB=
ILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)<br></div><div dir=3D"ltr=
">+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED O=
F THE<br></div><div dir=3D"ltr">+ * POSSIBILITY OF SUCH DAMAGE.<br></div><d=
iv dir=3D"ltr">+ */<br></div><div dir=3D"ltr">+#ifndef _SSP_SSP_H_<br></div=
><div dir=3D"ltr">+#define _SSP_SSP_H_<br></div><div dir=3D"ltr">+<br></div=
><div dir=3D"ltr">+#include &lt;sys/cdefs.h&gt;<br></div><div dir=3D"ltr">+=
<br></div><div dir=3D"ltr">+#if !defined(__cplusplus)<br></div><div dir=3D"=
ltr">+# if defined(_FORTIFY_SOURCE) &amp;&amp; _FORTIFY_SOURCE &gt; 0 &amp;=
&amp; \<br></div><div dir=3D"ltr">+&nbsp; &nbsp;  (__OPTIMIZE__ &gt; 0 || d=
efined(__clang__))<br></div><div dir=3D"ltr">+#&nbsp; if _FORTIFY_SOURCE &g=
t; 1<br></div><div dir=3D"ltr">+#&nbsp;  define __SSP_FORTIFY_LEVEL 2<br></=
div><div dir=3D"ltr">+#&nbsp; else<br></div><div dir=3D"ltr">+#&nbsp;  defi=
ne __SSP_FORTIFY_LEVEL 1<br></div><div dir=3D"ltr">+#&nbsp; endif<br></div>=
<div dir=3D"ltr">+# else<br></div><div dir=3D"ltr">+#&nbsp; define __SSP_FO=
RTIFY_LEVEL 0<br></div><div dir=3D"ltr">+# endif<br></div><div dir=3D"ltr">=
+#else<br></div><div dir=3D"ltr">+# define __SSP_FORTIFY_LEVEL 0<br></div><=
div dir=3D"ltr">+#endif<br></div><div dir=3D"ltr">+<br></div><div dir=3D"lt=
r">+#define&nbsp;&nbsp;&nbsp; __ssp_var(type)&nbsp;&nbsp;&nbsp; __CONCAT(__=
ssp_ ## type, __COUNTER__)<br></div><div dir=3D"ltr">+<br></div><div dir=3D=
"ltr">+/* __ssp_real is used by the implementation in libc */<br></div><div=
 dir=3D"ltr">+#if __SSP_FORTIFY_LEVEL =3D=3D 0<br></div><div dir=3D"ltr">+#=
define __ssp_real_(fun)&nbsp;&nbsp;&nbsp; fun<br></div><div dir=3D"ltr">+#e=
lse<br></div><div dir=3D"ltr">+#define __ssp_real_(fun)&nbsp;&nbsp;&nbsp; _=
_ssp_real_ ## fun<br></div><div dir=3D"ltr">+#endif<br></div><div dir=3D"lt=
r">+#define __ssp_real(fun)&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; __ssp_real=
_(fun)<br></div><div dir=3D"ltr">+<br></div><div dir=3D"ltr">+#define __ssp=
_inline static __inline __attribute__((__always_inline__))<br></div><div di=
r=3D"ltr">+<br></div><div dir=3D"ltr">+#define __ssp_bos(ptr) __builtin_obj=
ect_size(ptr, __SSP_FORTIFY_LEVEL &gt; 1)<br></div><div dir=3D"ltr">+#defin=
e __ssp_bos0(ptr) __builtin_object_size(ptr, 0)<br></div><div dir=3D"ltr">+=
<br></div><div dir=3D"ltr">+#define __ssp_check(buf, len, bos) \<br></div><=
div dir=3D"ltr">+&nbsp;&nbsp;&nbsp; if (bos(buf) !=3D (size_t)-1 &amp;&amp;=
 len &gt; bos(buf)) \<br></div><div dir=3D"ltr">+&nbsp;&nbsp;&nbsp; &nbsp;&=
nbsp;&nbsp; __chk_fail()<br></div><div dir=3D"ltr">+#define __ssp_redirect_=
raw(rtype, fun, symbol, args, call, cond, bos) \<br></div><div dir=3D"ltr">=
+rtype __ssp_real_(fun) args __RENAME(symbol); \<br></div><div dir=3D"ltr">=
+__ssp_inline rtype fun args __RENAME(__ssp_protected_ ## fun); \<br></div>=
<div dir=3D"ltr">+__ssp_inline rtype fun args { \<br></div><div dir=3D"ltr"=
>+&nbsp;&nbsp;&nbsp; if (cond) \<br></div><div dir=3D"ltr">+&nbsp;&nbsp;&nb=
sp; &nbsp;&nbsp;&nbsp; __ssp_check(__buf, __len, bos); \<br></div><div dir=
=3D"ltr">+&nbsp;&nbsp;&nbsp; return __ssp_real_(fun) call; \<br></div><div =
dir=3D"ltr">+}<br></div><div dir=3D"ltr">+<br></div><div dir=3D"ltr">+#defi=
ne __ssp_redirect(rtype, fun, args, call) \<br></div><div dir=3D"ltr">+&nbs=
p; &nbsp; __ssp_redirect_raw(rtype, fun, fun, args, call, 1, __ssp_bos)<br>=
</div><div dir=3D"ltr">+#define __ssp_redirect0(rtype, fun, args, call) \<b=
r></div><div dir=3D"ltr">+&nbsp; &nbsp; __ssp_redirect_raw(rtype, fun, fun,=
 args, call, 1, __ssp_bos0)<br></div><div dir=3D"ltr">+<br></div><div dir=
=3D"ltr">+__BEGIN_DECLS<br></div><div dir=3D"ltr">+void __stack_chk_fail(vo=
id) __dead2;<br></div><div dir=3D"ltr">+void __chk_fail(void) __dead2;<br><=
/div><div dir=3D"ltr">+__END_DECLS<br></div><div dir=3D"ltr">+<br></div><di=
v dir=3D"ltr">+#endif /* _SSP_SSP_H_ */<br></div><div dir=3D"ltr">diff --gi=
t a/include/ssp/stdio.h b/include/ssp/stdio.h<br></div><div dir=3D"ltr">new=
 file mode 100644<br></div><div dir=3D"ltr">index 000000000000..72e3236eac8=
0<br></div><div dir=3D"ltr">--- /dev/null<br></div><div dir=3D"ltr">+++ b/i=
nclude/ssp/stdio.h<br></div><div dir=3D"ltr">@@ -0,0 +1,93 @@<br></div><div=
 dir=3D"ltr">+/*&nbsp;&nbsp;&nbsp; $NetBSD: stdio.h,v 1.5 2011/07/17 20:54:=
34 joerg Exp $&nbsp;&nbsp;&nbsp; */<br></div><div dir=3D"ltr">+<br></div><d=
iv dir=3D"ltr">+/*-<br></div><div dir=3D"ltr">+ *<br></div><div dir=3D"ltr"=
>+ * SPDX-License-Identifier: BSD-2-Clause<br></div><div dir=3D"ltr">+ *<br=
></div><div dir=3D"ltr">+ * Copyright (c) 2006 The NetBSD Foundation, Inc.<=
br></div><div dir=3D"ltr">+ * All rights reserved.<br></div><div dir=3D"ltr=
">+ *<br></div><div dir=3D"ltr">+ * This code is derived from software cont=
ributed to The NetBSD Foundation<br></div><div dir=3D"ltr">+ * by Christos =
Zoulas.<br></div><div dir=3D"ltr">+ *<br></div><div dir=3D"ltr">+ * Redistr=
ibution and use in source and binary forms, with or without<br></div><div d=
ir=3D"ltr">+ * modification, are permitted provided that the following cond=
itions<br></div><div dir=3D"ltr">+ * are met:<br></div><div dir=3D"ltr">+ *=
 1. Redistributions of source code must retain the above copyright<br></div=
><div dir=3D"ltr">+ *&nbsp; &nbsp; notice, this list of conditions and the =
following disclaimer.<br></div><div dir=3D"ltr">+ * 2. Redistributions in b=
inary form must reproduce the above copyright<br></div><div dir=3D"ltr">+ *=
&nbsp; &nbsp; notice, this list of conditions and the following disclaimer =
in the<br></div><div dir=3D"ltr">+ *&nbsp; &nbsp; documentation and/or othe=
r materials provided with the distribution.<br></div><div dir=3D"ltr">+ *<b=
r></div><div dir=3D"ltr">+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDA=
TION, INC. AND CONTRIBUTORS<br></div><div dir=3D"ltr">+ * ``AS IS'' AND ANY=
 EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED<br></div><div di=
r=3D"ltr">+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR=
 A PARTICULAR<br></div><div dir=3D"ltr">+ * PURPOSE ARE DISCLAIMED.&nbsp; I=
N NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS<br></div><div dir=3D"ltr">+=
 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR<b=
r></div><div dir=3D"ltr">+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMI=
TED TO, PROCUREMENT OF<br></div><div dir=3D"ltr">+ * SUBSTITUTE GOODS OR SE=
RVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS<br></div><div dir=3D"ltr=
">+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER =
IN<br></div><div dir=3D"ltr">+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLU=
DING NEGLIGENCE OR OTHERWISE)<br></div><div dir=3D"ltr">+ * ARISING IN ANY =
WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE<br></div><div d=
ir=3D"ltr">+ * POSSIBILITY OF SUCH DAMAGE.<br></div><div dir=3D"ltr">+ */<b=
r></div><div dir=3D"ltr">+#ifndef _SSP_STDIO_H_<br></div><div dir=3D"ltr">+=
#define _SSP_STDIO_H_<br></div><div dir=3D"ltr">+<br></div><div dir=3D"ltr"=
>+#include &lt;ssp/ssp.h&gt;<br></div><div dir=3D"ltr">+<br></div><div dir=
=3D"ltr">+__BEGIN_DECLS<br></div><div dir=3D"ltr">+int __sprintf_chk(char *=
__restrict, int, size_t, const char *__restrict, ...)<br></div><div dir=3D"=
ltr">+&nbsp; &nbsp; __printflike(4, 5);<br></div><div dir=3D"ltr">+int __vs=
printf_chk(char *__restrict, int, size_t, const char *__restrict,<br></div>=
<div dir=3D"ltr">+&nbsp; &nbsp; __va_list)<br></div><div dir=3D"ltr">+&nbsp=
; &nbsp; __printflike(4, 0);<br></div><div dir=3D"ltr">+int __snprintf_chk(=
char *__restrict, size_t, int, size_t,<br></div><div dir=3D"ltr">+&nbsp; &n=
bsp; const char *__restrict, ...)<br></div><div dir=3D"ltr">+&nbsp; &nbsp; =
__printflike(5, 6);<br></div><div dir=3D"ltr">+int __vsnprintf_chk(char *__=
restrict, size_t, int, size_t,<br></div><div dir=3D"ltr">+&nbsp; &nbsp;  co=
nst char *__restrict, __va_list)<br></div><div dir=3D"ltr">+&nbsp; &nbsp; _=
_printflike(5, 0);<br></div><div dir=3D"ltr">+char *__gets_chk(char *, size=
_t);<br></div><div dir=3D"ltr">+char *__fgets_chk(char *, int, size_t, FILE=
 *);<br></div><div dir=3D"ltr">+__END_DECLS<br></div><div dir=3D"ltr">+<br>=
</div><div dir=3D"ltr">+#if __SSP_FORTIFY_LEVEL &gt; 0<br></div><div dir=3D=
"ltr">+<br></div><div dir=3D"ltr">+#define sprintf(str, ...) ({&nbsp;&nbsp;=
&nbsp; \<br></div><div dir=3D"ltr">+&nbsp; &nbsp; char *_ssp_str =3D (str);=
&nbsp;&nbsp;&nbsp; \<br></div><div dir=3D"ltr">+&nbsp; &nbsp; __builtin___s=
printf_chk(_ssp_str, 0, __ssp_bos(_ssp_str),&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;=
&nbsp; \<br></div><div dir=3D"ltr">+&nbsp; &nbsp; &nbsp; &nbsp; __VA_ARGS__=
); \<br></div><div dir=3D"ltr">+})<br></div><div dir=3D"ltr">+<br></div><di=
v dir=3D"ltr">+#define vsprintf(str, fmt, ap) ({&nbsp;&nbsp;&nbsp; \<br></d=
iv><div dir=3D"ltr">+&nbsp; &nbsp; char *_ssp_str =3D (str);&nbsp;&nbsp;&nb=
sp; &nbsp;&nbsp;&nbsp; \<br></div><div dir=3D"ltr">+&nbsp; &nbsp; __builtin=
___vsprintf_chk(_ssp_str, 0, __ssp_bos(_ssp_str), fmt,&nbsp;&nbsp;&nbsp; \<=
br></div><div dir=3D"ltr">+&nbsp; &nbsp; &nbsp; &nbsp; ap);&nbsp;&nbsp;&nbs=
p; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; \<br></div><div=
 dir=3D"ltr">+})<br></div><div dir=3D"ltr">+<br></div><div dir=3D"ltr">+#de=
fine snprintf(str, len, ...) ({&nbsp;&nbsp;&nbsp; \<br></div><div dir=3D"lt=
r">+&nbsp; &nbsp; char *_ssp_str =3D (str);&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&=
nbsp; \<br></div><div dir=3D"ltr">+&nbsp; &nbsp; __builtin___snprintf_chk(_=
ssp_str, len, 0, __ssp_bos(_ssp_str),&nbsp;&nbsp;&nbsp; \<br></div><div dir=
=3D"ltr">+&nbsp; &nbsp; &nbsp; &nbsp; __VA_ARGS__);&nbsp;&nbsp;&nbsp; &nbsp=
;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; \<br></div><div dir=3D"ltr">+})<br></div><=
div dir=3D"ltr">+<br></div><div dir=3D"ltr">+#define vsnprintf(str, len, fm=
t, ap) ({&nbsp;&nbsp;&nbsp; \<br></div><div dir=3D"ltr">+&nbsp; &nbsp; char=
 *_ssp_str =3D (str);&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; \<br></div><div =
dir=3D"ltr">+&nbsp; &nbsp; __builtin___vsnprintf_chk(_ssp_str, len, 0, __ss=
p_bos(_ssp_str),&nbsp;&nbsp;&nbsp; \<br></div><div dir=3D"ltr">+&nbsp; &nbs=
p; &nbsp; &nbsp; fmt, ap);&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp=
;&nbsp; \<br></div><div dir=3D"ltr">+})<br></div><div dir=3D"ltr">+<br></di=
v><div dir=3D"ltr">+#define gets(str) ({&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbs=
p; &nbsp;&nbsp;&nbsp; \<br></div><div dir=3D"ltr">+&nbsp;  char *_ssp_str =
=3D (str);&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; \<br></div><div dir=3D"ltr"=
>+&nbsp; &nbsp; __gets_chk(_ssp_str, __ssp_bos(_ssp_str));&nbsp;&nbsp;&nbsp=
; \<br></div><div dir=3D"ltr">+})<br></div><div dir=3D"ltr">+<br></div><div=
 dir=3D"ltr">+#define fgets(str, len, fp) ({&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;=
&nbsp; \<br></div><div dir=3D"ltr">+&nbsp; &nbsp; char *_ssp_str =3D (str);=
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; \<br></div><div dir=3D"ltr">+&nbsp; &=
nbsp; __fgets_chk(_ssp_str, len, __ssp_bos(_ssp_str), fp);&nbsp;&nbsp;&nbsp=
; \<br></div><div dir=3D"ltr">+})<br></div><div dir=3D"ltr">+<br></div><div=
 dir=3D"ltr">+#endif /* __SSP_FORTIFY_LEVEL &gt; 0 */<br></div><div dir=3D"=
ltr">+<br></div><div dir=3D"ltr">+#endif /* _SSP_STDIO_H_ */<br></div><div =
dir=3D"ltr">diff --git a/include/ssp/string.h b/include/ssp/string.h<br></d=
iv><div dir=3D"ltr">new file mode 100644<br></div><div dir=3D"ltr">index 00=
0000000000..996020fda778<br></div><div dir=3D"ltr">--- /dev/null<br></div><=
div dir=3D"ltr">+++ b/include/ssp/string.h<br></div><div dir=3D"ltr">@@ -0,=
0 +1,129 @@<br></div><div dir=3D"ltr">+/*&nbsp;&nbsp;&nbsp; $NetBSD: string=
.h,v 1.14 2020/09/05 13:37:59 mrg Exp $&nbsp;&nbsp;&nbsp; */<br></div><div =
dir=3D"ltr">+<br></div><div dir=3D"ltr">+/*-<br></div><div dir=3D"ltr">+ *<=
br></div><div dir=3D"ltr">+ * SPDX-License-Identifier: BSD-2-Clause<br></di=
v><div dir=3D"ltr">+ *<br></div><div dir=3D"ltr">+ * Copyright (c) 2006 The=
 NetBSD Foundation, Inc.<br></div><div dir=3D"ltr">+ * All rights reserved.=
<br></div><div dir=3D"ltr">+ *<br></div><div dir=3D"ltr">+ * This code is d=
erived from software contributed to The NetBSD Foundation<br></div><div dir=
=3D"ltr">+ * by Christos Zoulas.<br></div><div dir=3D"ltr">+ *<br></div><di=
v dir=3D"ltr">+ * Redistribution and use in source and binary forms, with o=
r without<br></div><div dir=3D"ltr">+ * modification, are permitted provide=
d that the following conditions<br></div><div dir=3D"ltr">+ * are met:<br><=
/div><div dir=3D"ltr">+ * 1. Redistributions of source code must retain the=
 above copyright<br></div><div dir=3D"ltr">+ *&nbsp; &nbsp; notice, this li=
st of conditions and the following disclaimer.<br></div><div dir=3D"ltr">+ =
* 2. Redistributions in binary form must reproduce the above copyright<br><=
/div><div dir=3D"ltr">+ *&nbsp; &nbsp; notice, this list of conditions and =
the following disclaimer in the<br></div><div dir=3D"ltr">+ *&nbsp; &nbsp; =
documentation and/or other materials provided with the distribution.<br></d=
iv><div dir=3D"ltr">+ *<br></div><div dir=3D"ltr">+ * THIS SOFTWARE IS PROV=
IDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS<br></div><div dir=3D"l=
tr">+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT=
 LIMITED<br></div><div dir=3D"ltr">+ * TO, THE IMPLIED WARRANTIES OF MERCHA=
NTABILITY AND FITNESS FOR A PARTICULAR<br></div><div dir=3D"ltr">+ * PURPOS=
E ARE DISCLAIMED.&nbsp; IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS<br=
></div><div dir=3D"ltr">+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,=
 SPECIAL, EXEMPLARY, OR<br></div><div dir=3D"ltr">+ * CONSEQUENTIAL DAMAGES=
 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF<br></div><div dir=3D"ltr">+=
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS=
<br></div><div dir=3D"ltr">+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEO=
RY OF LIABILITY, WHETHER IN<br></div><div dir=3D"ltr">+ * CONTRACT, STRICT =
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)<br></div><div dir=3D=
"ltr">+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVIS=
ED OF THE<br></div><div dir=3D"ltr">+ * POSSIBILITY OF SUCH DAMAGE.<br></di=
v><div dir=3D"ltr">+ */<br></div><div dir=3D"ltr">+#ifndef _SSP_STRING_H_<b=
r></div><div dir=3D"ltr">+#define _SSP_STRING_H_<br></div><div dir=3D"ltr">=
+<br></div><div dir=3D"ltr">+#include &lt;ssp/ssp.h&gt;<br></div><div dir=
=3D"ltr">+<br></div><div dir=3D"ltr">+__BEGIN_DECLS<br></div><div dir=3D"lt=
r">+void *__memcpy_chk(void *, const void *, size_t, size_t);<br></div><div=
 dir=3D"ltr">+void *__memmove_chk(void *, const void *, size_t, size_t);<br=
></div><div dir=3D"ltr">+void *__memset_chk(void *, int, size_t, size_t);<b=
r></div><div dir=3D"ltr">+char *__stpcpy_chk(char *, const char *, size_t);=
<br></div><div dir=3D"ltr">+char *__stpncpy_chk(char *, const char *, size_=
t, size_t);<br></div><div dir=3D"ltr">+char *__strcat_chk(char *, const cha=
r *, size_t);<br></div><div dir=3D"ltr">+char *__strcpy_chk(char *, const c=
har *, size_t);<br></div><div dir=3D"ltr">+char *__strncat_chk(char *, cons=
t char *, size_t, size_t);<br></div><div dir=3D"ltr">+char *__strncpy_chk(c=
har *, const char *, size_t, size_t);<br></div><div dir=3D"ltr">+__END_DECL=
S<br></div><div dir=3D"ltr">+<br></div><div dir=3D"ltr">+#if __SSP_FORTIFY_=
LEVEL &gt; 0<br></div><div dir=3D"ltr">+<br></div><div dir=3D"ltr">+#define=
 __ssp_bos_check3_typed_var(fun, dsttype, dsrvar, dst, srctype, srcvar, \<b=
r></div><div dir=3D"ltr">+&nbsp; &nbsp; src, lenvar, len) ({&nbsp;&nbsp;&nb=
sp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; \<br></div><di=
v dir=3D"ltr">+&nbsp; &nbsp; srctype srcvar =3D (src);&nbsp;&nbsp;&nbsp; &n=
bsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; \<br></div><div dir=
=3D"ltr">+&nbsp; &nbsp; dsttype dstvar =3D (dst);&nbsp;&nbsp;&nbsp; &nbsp;&=
nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; \<br></div><div dir=3D"lt=
r">+&nbsp; &nbsp; size_t lenvar =3D (len);&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&n=
bsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; \<br></div><div dir=3D"ltr">+&nb=
sp; &nbsp; ((__ssp_bos0(dstvar) !=3D (size_t)-1) ?&nbsp;&nbsp;&nbsp; &nbsp;=
&nbsp;&nbsp; \<br></div><div dir=3D"ltr">+&nbsp; &nbsp; __builtin___ ## fun=
 ## _chk(dstvar, srcvar, lenvar,&nbsp;&nbsp;&nbsp; \<br></div><div dir=3D"l=
tr">+&nbsp; &nbsp; &nbsp; &nbsp; __ssp_bos0(dstvar)) :&nbsp;&nbsp;&nbsp; &n=
bsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; \<br></div><div dir=
=3D"ltr">+&nbsp; &nbsp; __ ## fun ## _ichk(dstvar, srcvar, lenvar));&nbsp;&=
nbsp;&nbsp; \<br></div><div dir=3D"ltr">+})<br></div><div dir=3D"ltr">+<br>=
</div><div dir=3D"ltr">+#define __ssp_bos_check3_typed(fun, dsttype, dst, s=
rctype, src, len)&nbsp;&nbsp;&nbsp; \<br></div><div dir=3D"ltr">+&nbsp; &nb=
sp; __ssp_bos_check3_typed_var(fun, dsttype, __ssp_var(dstv), dst,&nbsp;&nb=
sp;&nbsp; \<br></div><div dir=3D"ltr">+&nbsp; &nbsp; &nbsp; &nbsp; srctype,=
 __ssp_var(srcv), src, __ssp_var(lenv), len)<br></div><div dir=3D"ltr">+<br=
></div><div dir=3D"ltr">+#define __ssp_bos_check3(fun, dst, src, len)&nbsp;=
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; \<br></div><div dir=3D"ltr">+&nbsp; &nbsp; =
__ssp_bos_check3_typed_var(fun, void *, __ssp_var(dstv), dst,&nbsp;&nbsp;&n=
bsp; \<br></div><div dir=3D"ltr">+&nbsp; &nbsp; &nbsp; &nbsp; const void *,=
 __ssp_var(srcv), src, __ssp_var(lenv), len)<br></div><div dir=3D"ltr">+<br=
></div><div dir=3D"ltr">+#define __ssp_bos_check2_var(fun, dstvar, dst, src=
var, src) ({&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; \<br></div><div dir=3D"lt=
r">+&nbsp; &nbsp; const void *srcvar =3D (src);&nbsp;&nbsp;&nbsp; &nbsp;&nb=
sp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; \<br></div><div dir=3D"ltr"=
>+&nbsp; &nbsp; void *dstvar =3D (dst);&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp=
; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; \<br></div><div dir=3D"ltr">+&nbsp;=
 &nbsp; ((__ssp_bos0(dstvar) !=3D (size_t)-1) ?&nbsp;&nbsp;&nbsp; &nbsp;&nb=
sp;&nbsp; \<br></div><div dir=3D"ltr">+&nbsp; &nbsp; __builtin___ ## fun ##=
 _chk(dstvar, srcvar,&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; \<br></div><div =
dir=3D"ltr">+&nbsp; &nbsp; &nbsp; &nbsp; __ssp_bos0(dstvar)) :&nbsp;&nbsp;&=
nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; \<br></div><=
div dir=3D"ltr">+&nbsp; &nbsp; __ ## fun ## _ichk(dstvar, srcvar));&nbsp;&n=
bsp;&nbsp; &nbsp;&nbsp;&nbsp; \<br></div><div dir=3D"ltr">+})<br></div><div=
 dir=3D"ltr">+<br></div><div dir=3D"ltr">+#define __ssp_bos_check2(fun, dst=
, src)&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; \<br></div><=
div dir=3D"ltr">+&nbsp; &nbsp; __ssp_bos_check2_var(fun, __ssp_var(dstv), d=
st, __ssp_var(srcv), src)<br></div><div dir=3D"ltr">+<br></div><div dir=3D"=
ltr">+#define __ssp_bos_icheck3_restrict(fun, type1, type2) \<br></div><div=
 dir=3D"ltr">+static __inline type1 __ ## fun ## _ichk(type1 __restrict, ty=
pe2 __restrict, size_t); \<br></div><div dir=3D"ltr">+static __inline __att=
ribute__((__always_inline__)) type1 \<br></div><div dir=3D"ltr">+__ ## fun =
## _ichk(type1 __restrict dst, type2 __restrict src, size_t len) { \<br></d=
iv><div dir=3D"ltr">+&nbsp;&nbsp;&nbsp; return __builtin___ ## fun ## _chk(=
dst, src, len, __ssp_bos0(dst)); \<br></div><div dir=3D"ltr">+}<br></div><d=
iv dir=3D"ltr">+<br></div><div dir=3D"ltr">+#define __ssp_bos_icheck3(fun, =
type1, type2) \<br></div><div dir=3D"ltr">+static __inline type1 __ ## fun =
## _ichk(type1, type2, size_t); \<br></div><div dir=3D"ltr">+static __inlin=
e __attribute__((__always_inline__)) type1 \<br></div><div dir=3D"ltr">+__ =
## fun ## _ichk(type1 dst, type2 src, size_t len) { \<br></div><div dir=3D"=
ltr">+&nbsp;&nbsp;&nbsp; return __builtin___ ## fun ## _chk(dst, src, len, =
__ssp_bos0(dst)); \<br></div><div dir=3D"ltr">+}<br></div><div dir=3D"ltr">=
+<br></div><div dir=3D"ltr">+#define __ssp_bos_icheck2_restrict(fun, type1,=
 type2) \<br></div><div dir=3D"ltr">+static __inline type1 __ ## fun ## _ic=
hk(type1, type2); \<br></div><div dir=3D"ltr">+static __inline __attribute_=
_((__always_inline__)) type1 \<br></div><div dir=3D"ltr">+__ ## fun ## _ich=
k(type1 __restrict dst, type2 __restrict src) { \<br></div><div dir=3D"ltr"=
>+&nbsp;&nbsp;&nbsp; return __builtin___ ## fun ## _chk(dst, src, __ssp_bos=
0(dst)); \<br></div><div dir=3D"ltr">+}<br></div><div dir=3D"ltr">+<br></di=
v><div dir=3D"ltr">+__BEGIN_DECLS<br></div><div dir=3D"ltr">+__ssp_bos_iche=
ck3_restrict(memcpy, void *, const void *)<br></div><div dir=3D"ltr">+__ssp=
_bos_icheck3(memmove, void *, const void *)<br></div><div dir=3D"ltr">+__ss=
p_bos_icheck3(memset, void *, int)<br></div><div dir=3D"ltr">+__ssp_bos_ich=
eck2_restrict(stpcpy, char *, const char *)<br></div><div dir=3D"ltr">+__ss=
p_bos_icheck3_restrict(stpncpy, char *, const char *)<br></div><div dir=3D"=
ltr">+__ssp_bos_icheck2_restrict(strcpy, char *, const char *)<br></div><di=
v dir=3D"ltr">+__ssp_bos_icheck2_restrict(strcat, char *, const char *)<br>=
</div><div dir=3D"ltr">+__ssp_bos_icheck3_restrict(strncpy, char *, const c=
har *)<br></div><div dir=3D"ltr">+__ssp_bos_icheck3_restrict(strncat, char =
*, const char *)<br></div><div dir=3D"ltr">+__END_DECLS<br></div><div dir=
=3D"ltr">+<br></div><div dir=3D"ltr">+#define memcpy(dst, src, len) __ssp_b=
os_check3(memcpy, dst, src, len)<br></div><div dir=3D"ltr">+#define memmove=
(dst, src, len) __ssp_bos_check3(memmove, dst, src, len)<br></div><div dir=
=3D"ltr">+#define memset(dst, val, len) \<br></div><div dir=3D"ltr">+&nbsp;=
 &nbsp; __ssp_bos_check3_typed(memset, void *, dst, int, val, len)<br></div=
><div dir=3D"ltr">+#define stpcpy(dst, src) __ssp_bos_check2(stpcpy, dst, s=
rc)<br></div><div dir=3D"ltr">+#define stpncpy(dst, src, len) __ssp_bos_che=
ck3(stpncpy, dst, src, len)<br></div><div dir=3D"ltr">+#define strcpy(dst, =
src) __ssp_bos_check2(strcpy, dst, src)<br></div><div dir=3D"ltr">+#define =
strcat(dst, src) __ssp_bos_check2(strcat, dst, src)<br></div><div dir=3D"lt=
r">+#define strncpy(dst, src, len) __ssp_bos_check3(strncpy, dst, src, len)=
<br></div><div dir=3D"ltr">+#define strncat(dst, src, len) __ssp_bos_check3=
(strncat, dst, src, len)<br></div><div dir=3D"ltr">+<br></div><div dir=3D"l=
tr">+#endif /* __SSP_FORTIFY_LEVEL &gt; 0 */<br></div><div dir=3D"ltr">+#en=
dif /* _SSP_STRING_H_ */<br></div><div dir=3D"ltr">diff --git a/include/ssp=
/strings.h b/include/ssp/strings.h<br></div><div dir=3D"ltr">new file mode =
100644<br></div><div dir=3D"ltr">index 000000000000..06c9c7cc0a09<br></div>=
<div dir=3D"ltr">--- /dev/null<br></div><div dir=3D"ltr">+++ b/include/ssp/=
strings.h<br></div><div dir=3D"ltr">@@ -0,0 +1,67 @@<br></div><div dir=3D"l=
tr">+/*&nbsp;&nbsp;&nbsp; $NetBSD: strings.h,v 1.3 2008/04/28 20:22:54 mart=
in Exp $&nbsp;&nbsp;&nbsp; */<br></div><div dir=3D"ltr">+<br></div><div dir=
=3D"ltr">+/*-<br></div><div dir=3D"ltr">+ *<br></div><div dir=3D"ltr">+ * S=
PDX-License-Identifier: BSD-2-Clause<br></div><div dir=3D"ltr">+ *<br></div=
><div dir=3D"ltr">+ * Copyright (c) 2007 The NetBSD Foundation, Inc.<br></d=
iv><div dir=3D"ltr">+ * All rights reserved.<br></div><div dir=3D"ltr">+ *<=
br></div><div dir=3D"ltr">+ * This code is derived from software contribute=
d to The NetBSD Foundation<br></div><div dir=3D"ltr">+ * by Christos Zoulas=
.<br></div><div dir=3D"ltr">+ *<br></div><div dir=3D"ltr">+ * Redistributio=
n and use in source and binary forms, with or without<br></div><div dir=3D"=
ltr">+ * modification, are permitted provided that the following conditions=
<br></div><div dir=3D"ltr">+ * are met:<br></div><div dir=3D"ltr">+ * 1. Re=
distributions of source code must retain the above copyright<br></div><div =
dir=3D"ltr">+ *&nbsp; &nbsp; notice, this list of conditions and the follow=
ing disclaimer.<br></div><div dir=3D"ltr">+ * 2. Redistributions in binary =
form must reproduce the above copyright<br></div><div dir=3D"ltr">+ *&nbsp;=
 &nbsp; notice, this list of conditions and the following disclaimer in the=
<br></div><div dir=3D"ltr">+ *&nbsp; &nbsp; documentation and/or other mate=
rials provided with the distribution.<br></div><div dir=3D"ltr">+ *<br></di=
v><div dir=3D"ltr">+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, =
INC. AND CONTRIBUTORS<br></div><div dir=3D"ltr">+ * ``AS IS'' AND ANY EXPRE=
SS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED<br></div><div dir=3D"l=
tr">+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PAR=
TICULAR<br></div><div dir=3D"ltr">+ * PURPOSE ARE DISCLAIMED.&nbsp; IN NO E=
VENT SHALL THE FOUNDATION OR CONTRIBUTORS<br></div><div dir=3D"ltr">+ * BE =
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR<br></di=
v><div dir=3D"ltr">+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO=
, PROCUREMENT OF<br></div><div dir=3D"ltr">+ * SUBSTITUTE GOODS OR SERVICES=
; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS<br></div><div dir=3D"ltr">+ * =
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN<br>=
</div><div dir=3D"ltr">+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING N=
EGLIGENCE OR OTHERWISE)<br></div><div dir=3D"ltr">+ * ARISING IN ANY WAY OU=
T OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE<br></div><div dir=3D"=
ltr">+ * POSSIBILITY OF SUCH DAMAGE.<br></div><div dir=3D"ltr">+ */<br></di=
v><div dir=3D"ltr">+#ifndef _SSP_STRINGS_H_<br></div><div dir=3D"ltr">+#def=
ine _SSP_STRINGS_H_<br></div><div dir=3D"ltr">+<br></div><div dir=3D"ltr">+=
#include &lt;ssp/ssp.h&gt;<br></div><div dir=3D"ltr">+#include &lt;string.h=
&gt;<br></div><div dir=3D"ltr">+<br></div><div dir=3D"ltr">+#if __SSP_FORTI=
FY_LEVEL &gt; 0<br></div><div dir=3D"ltr">+<br></div><div dir=3D"ltr">+#def=
ine _ssp_bcopy(srcvar, src, dstvar, dst, lenvar,&nbsp; len) ({&nbsp;&nbsp;&=
nbsp; \<br></div><div dir=3D"ltr">+&nbsp; &nbsp; const void *srcvar =3D (sr=
c);&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; \<br></div><div=
 dir=3D"ltr">+&nbsp; &nbsp; void *dstvar =3D (dst);&nbsp;&nbsp;&nbsp; &nbsp=
;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; \<br></div><div dir=3D"ltr">+&nbsp; &nbsp;=
 size_t lenvar =3D (len);&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;=
&nbsp; \<br></div><div dir=3D"ltr">+&nbsp; &nbsp; ((__ssp_bos0(dstvar) !=3D=
 (size_t)-1) ?&nbsp;&nbsp;&nbsp; \<br></div><div dir=3D"ltr">+&nbsp; &nbsp;=
 __builtin___memmove_chk(dstvar, srcvar, lenvar,&nbsp;&nbsp;&nbsp; \<br></d=
iv><div dir=3D"ltr">+&nbsp; &nbsp; &nbsp; &nbsp; __ssp_bos0(dstvar)) :&nbsp=
;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; \<br></div><div dir=3D"=
ltr">+&nbsp; &nbsp; __memmove_ichk(dstvar, srcvar, lenvar));&nbsp;&nbsp;&nb=
sp; \<br></div><div dir=3D"ltr">+})<br></div><div dir=3D"ltr">+<br></div><d=
iv dir=3D"ltr">+#define&nbsp;&nbsp;&nbsp; bcopy(src, dst, len)&nbsp;&nbsp;&=
nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; \<br></div><div dir=3D"ltr">+&n=
bsp; &nbsp; _ssp_bcopy(__ssp_var(srcv), src, __ssp_var(dstv), dst, __ssp_va=
r(lenv), len)<br></div><div dir=3D"ltr">+<br></div><div dir=3D"ltr">+#defin=
e _ssp_bzero(dstvar, dst, lenvar, len) ({&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nb=
sp; \<br></div><div dir=3D"ltr">+&nbsp; &nbsp; void *dstvar =3D (dst);&nbsp=
;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; \<br></div><div dir=3D"=
ltr">+&nbsp; &nbsp; size_t lenvar =3D (len);&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;=
&nbsp; &nbsp;&nbsp;&nbsp; \<br></div><div dir=3D"ltr">+&nbsp; &nbsp; ((__ss=
p_bos0(dstvar) !=3D (size_t)-1) ?&nbsp;&nbsp;&nbsp; \<br></div><div dir=3D"=
ltr">+&nbsp; &nbsp; __builtin___memset_chk(dstvar, 0, lenvar,&nbsp;&nbsp;&n=
bsp; \<br></div><div dir=3D"ltr">+&nbsp; &nbsp; &nbsp; &nbsp; __ssp_bos0(ds=
tvar)) : \<br></div><div dir=3D"ltr">+&nbsp; &nbsp; __memset_ichk(dstvar, 0=
, lenvar));&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; \<br></div><div dir=3D"ltr=
">+})<br></div><div dir=3D"ltr">+<br></div><div dir=3D"ltr">+#define&nbsp;&=
nbsp;&nbsp; bzero(dst, len)&nbsp;&nbsp;&nbsp; _ssp_bzero(__ssp_var(dstv), d=
st, __ssp_var(lenv), len)<br></div><div dir=3D"ltr">+<br></div><div dir=3D"=
ltr">+#endif /* __SSP_FORTIFY_LEVEL &gt; 0 */<br></div><div dir=3D"ltr">+#e=
ndif /* _SSP_STRINGS_H_ */<br></div><div dir=3D"ltr">diff --git a/include/s=
sp/unistd.h b/include/ssp/unistd.h<br></div><div dir=3D"ltr">new file mode =
100644<br></div><div dir=3D"ltr">index 000000000000..2414e2baa96b<br></div>=
<div dir=3D"ltr">--- /dev/null<br></div><div dir=3D"ltr">+++ b/include/ssp/=
unistd.h<br></div><div dir=3D"ltr">@@ -0,0 +1,54 @@<br></div><div dir=3D"lt=
r">+/*&nbsp;&nbsp;&nbsp; $NetBSD: unistd.h,v 1.7 2015/06/25 18:41:03 joerg =
Exp $&nbsp;&nbsp;&nbsp; */<br></div><div dir=3D"ltr">+<br></div><div dir=3D=
"ltr">+/*-<br></div><div dir=3D"ltr">+ *<br></div><div dir=3D"ltr">+ * SPDX=
-License-Identifier: BSD-2-Clause<br></div><div dir=3D"ltr">+ *<br></div><d=
iv dir=3D"ltr">+ * Copyright (c) 2006 The NetBSD Foundation, Inc.<br></div>=
<div dir=3D"ltr">+ * All rights reserved.<br></div><div dir=3D"ltr">+ *<br>=
</div><div dir=3D"ltr">+ * This code is derived from software contributed t=
o The NetBSD Foundation<br></div><div dir=3D"ltr">+ * by Christos Zoulas.<b=
r></div><div dir=3D"ltr">+ *<br></div><div dir=3D"ltr">+ * Redistribution a=
nd use in source and binary forms, with or without<br></div><div dir=3D"ltr=
">+ * modification, are permitted provided that the following conditions<br=
></div><div dir=3D"ltr">+ * are met:<br></div><div dir=3D"ltr">+ * 1. Redis=
tributions of source code must retain the above copyright<br></div><div dir=
=3D"ltr">+ *&nbsp; &nbsp; notice, this list of conditions and the following=
 disclaimer.<br></div><div dir=3D"ltr">+ * 2. Redistributions in binary for=
m must reproduce the above copyright<br></div><div dir=3D"ltr">+ *&nbsp; &n=
bsp; notice, this list of conditions and the following disclaimer in the<br=
></div><div dir=3D"ltr">+ *&nbsp; &nbsp; documentation and/or other materia=
ls provided with the distribution.<br></div><div dir=3D"ltr">+ *<br></div><=
div dir=3D"ltr">+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC=
. AND CONTRIBUTORS<br></div><div dir=3D"ltr">+ * ``AS IS'' AND ANY EXPRESS =
OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED<br></div><div dir=3D"ltr"=
>+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTIC=
ULAR<br></div><div dir=3D"ltr">+ * PURPOSE ARE DISCLAIMED.&nbsp; IN NO EVEN=
T SHALL THE FOUNDATION OR CONTRIBUTORS<br></div><div dir=3D"ltr">+ * BE LIA=
BLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR<br></div><=
div dir=3D"ltr">+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, P=
ROCUREMENT OF<br></div><div dir=3D"ltr">+ * SUBSTITUTE GOODS OR SERVICES; L=
OSS OF USE, DATA, OR PROFITS; OR BUSINESS<br></div><div dir=3D"ltr">+ * INT=
ERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN<br></d=
iv><div dir=3D"ltr">+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGL=
IGENCE OR OTHERWISE)<br></div><div dir=3D"ltr">+ * ARISING IN ANY WAY OUT O=
F THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE<br></div><div dir=3D"ltr=
">+ * POSSIBILITY OF SUCH DAMAGE.<br></div><div dir=3D"ltr">+ */<br></div><=
div dir=3D"ltr">+#ifndef _SSP_UNISTD_H_<br></div><div dir=3D"ltr">+#define =
_SSP_UNISTD_H_<br></div><div dir=3D"ltr">+<br></div><div dir=3D"ltr">+#incl=
ude &lt;ssp/ssp.h&gt;<br></div><div dir=3D"ltr">+<br></div><div dir=3D"ltr"=
>+#if __SSP_FORTIFY_LEVEL &gt; 0<br></div><div dir=3D"ltr">+__BEGIN_DECLS<b=
r></div><div dir=3D"ltr">+<br></div><div dir=3D"ltr">+__ssp_redirect0(ssize=
_t, read, (int __fd, void *__buf, size_t __len), \<br></div><div dir=3D"ltr=
">+&nbsp; &nbsp; (__fd, __buf, __len));<br></div><div dir=3D"ltr">+<br></di=
v><div dir=3D"ltr">+__ssp_redirect(ssize_t, readlink, (const char *__restri=
ct __path, \<br></div><div dir=3D"ltr">+&nbsp; &nbsp; char *__restrict __bu=
f, size_t __len), (__path, __buf, __len));<br></div><div dir=3D"ltr">+<br><=
/div><div dir=3D"ltr">+__ssp_redirect_raw(char *, getcwd, getcwd, (char *__=
buf, size_t __len),<br></div><div dir=3D"ltr">+&nbsp; &nbsp; (__buf, __len)=
, __buf !=3D 0, __ssp_bos);<br></div><div dir=3D"ltr">+<br></div><div dir=
=3D"ltr">+__END_DECLS<br></div><div dir=3D"ltr">+<br></div><div dir=3D"ltr"=
>+#endif /* __SSP_FORTIFY_LEVEL &gt; 0 */<br></div><div dir=3D"ltr">+#endif=
 /* _SSP_UNISTD_H_ */<br></div><div dir=3D"ltr">diff --git a/lib/libc/secur=
e/Makefile.inc b/lib/libc/secure/Makefile.inc<br></div><div dir=3D"ltr">ind=
ex 8574c5a05dc5..3b1ad879c715 100644<br></div><div dir=3D"ltr">--- a/lib/li=
bc/secure/Makefile.inc<br></div><div dir=3D"ltr">+++ b/lib/libc/secure/Make=
file.inc<br></div><div dir=3D"ltr">@@ -3,6 +3,17 @@<br></div><div dir=3D"lt=
r"> <br></div><div dir=3D"ltr"> .PATH: ${LIBC_SRCTOP}/secure<br></div><div =
dir=3D"ltr"> <br></div><div dir=3D"ltr">+# _FORTIFY_SOURCE<br></div><div di=
r=3D"ltr">+SRCS+=3D&nbsp;&nbsp;&nbsp; gets_chk.c fgets_chk.c memcpy_chk.c m=
emmove_chk.c memset_chk.c \<br></div><div dir=3D"ltr">+&nbsp;&nbsp;&nbsp; s=
nprintf_chk.c sprintf_chk.c stpcpy_chk.c stpncpy_chk.c \<br></div><div dir=
=3D"ltr">+&nbsp;&nbsp;&nbsp; strcat_chk.c strcpy_chk.c strncat_chk.c strncp=
y_chk.c \<br></div><div dir=3D"ltr">+&nbsp;&nbsp;&nbsp; vsnprintf_chk.c vsp=
rintf_chk.c<br></div><div dir=3D"ltr">+<br></div><div dir=3D"ltr">+CFLAGS.s=
nprintf_chk.c+=3D&nbsp;&nbsp;&nbsp; -Wno-unused-parameter<br></div><div dir=
=3D"ltr">+CFLAGS.sprintf_chk.c+=3D&nbsp;&nbsp;&nbsp; -Wno-unused-parameter<=
br></div><div dir=3D"ltr">+CFLAGS.vsnprintf_chk.c+=3D&nbsp;&nbsp;&nbsp; -Wn=
o-unused-parameter<br></div><div dir=3D"ltr">+CFLAGS.vsprintf_chk.c+=3D&nbs=
p;&nbsp;&nbsp; -Wno-unused-parameter<br></div><div dir=3D"ltr">+<br></div><=
div dir=3D"ltr"> # Sources common to both syscall interfaces:<br></div><div=
 dir=3D"ltr"> SRCS+=3D&nbsp;&nbsp;&nbsp; stack_protector.c \<br></div><div =
dir=3D"ltr"> &nbsp;&nbsp;&nbsp; stack_protector_compat.c<br></div><div dir=
=3D"ltr">diff --git a/lib/libc/secure/Symbol.map b/lib/libc/secure/Symbol.m=
ap<br></div><div dir=3D"ltr">index 641f451b5421..7859fcee3821 100644<br></d=
iv><div dir=3D"ltr">--- a/lib/libc/secure/Symbol.map<br></div><div dir=3D"l=
tr">+++ b/lib/libc/secure/Symbol.map<br></div><div dir=3D"ltr">@@ -3,3 +3,2=
1 @@ FBSD_1.0 {<br></div><div dir=3D"ltr"> &nbsp;&nbsp;&nbsp; __stack_chk_f=
ail;<br></div><div dir=3D"ltr"> &nbsp;&nbsp;&nbsp; __stack_chk_guard;<br></=
div><div dir=3D"ltr"> };<br></div><div dir=3D"ltr">+<br></div><div dir=3D"l=
tr">+FBSD_1.8 {<br></div><div dir=3D"ltr">+&nbsp;&nbsp;&nbsp; __gets_chk;<b=
r></div><div dir=3D"ltr">+&nbsp;&nbsp;&nbsp; __fgets_chk;<br></div><div dir=
=3D"ltr">+&nbsp;&nbsp;&nbsp; __memcpy_chk;<br></div><div dir=3D"ltr">+&nbsp=
;&nbsp;&nbsp; __memmove_chk;<br></div><div dir=3D"ltr">+&nbsp;&nbsp;&nbsp; =
__memset_chk;<br></div><div dir=3D"ltr">+&nbsp;&nbsp;&nbsp; __snprintf_chk;=
<br></div><div dir=3D"ltr">+&nbsp;&nbsp;&nbsp; __sprintf_chk;<br></div><div=
 dir=3D"ltr">+&nbsp;&nbsp;&nbsp; __stpcpy_chk;<br></div><div dir=3D"ltr">+&=
nbsp;&nbsp;&nbsp; __stpncpy_chk;<br></div><div dir=3D"ltr">+&nbsp;&nbsp;&nb=
sp; __strcat_chk;<br></div><div dir=3D"ltr">+&nbsp;&nbsp;&nbsp; __strcpy_ch=
k;<br></div><div dir=3D"ltr">+&nbsp;&nbsp;&nbsp; __strncat_chk;<br></div><d=
iv dir=3D"ltr">+&nbsp;&nbsp;&nbsp; __strncpy_chk;<br></div><div dir=3D"ltr"=
>+&nbsp;&nbsp;&nbsp; __vsnprintf_chk;<br></div><div dir=3D"ltr">+&nbsp;&nbs=
p;&nbsp; __vsprintf_chk;<br></div><div dir=3D"ltr">+};<br></div><div dir=3D=
"ltr">diff --git a/lib/libc/secure/fgets_chk.c b/lib/libc/secure/fgets_chk.=
c<br></div><div dir=3D"ltr">new file mode 100644<br></div><div dir=3D"ltr">=
index 000000000000..72aa1d816ce1<br></div><div dir=3D"ltr">--- /dev/null<br=
></div><div dir=3D"ltr">+++ b/lib/libc/secure/fgets_chk.c<br></div><div dir=
=3D"ltr">@@ -0,0 +1,54 @@<br></div><div dir=3D"ltr">+/*-<br></div><div dir=
=3D"ltr">+ *<br></div><div dir=3D"ltr">+ * SPDX-License-Identifier: BSD-2-C=
lause<br></div><div dir=3D"ltr">+ *<br></div><div dir=3D"ltr">+ * Copyright=
 (c) 2006 The NetBSD Foundation, Inc.<br></div><div dir=3D"ltr">+ * All rig=
hts reserved.<br></div><div dir=3D"ltr">+ *<br></div><div dir=3D"ltr">+ * T=
his code is derived from software contributed to The NetBSD Foundation<br><=
/div><div dir=3D"ltr">+ * by Christos Zoulas.<br></div><div dir=3D"ltr">+ *=
<br></div><div dir=3D"ltr">+ * Redistribution and use in source and binary =
forms, with or without<br></div><div dir=3D"ltr">+ * modification, are perm=
itted provided that the following conditions<br></div><div dir=3D"ltr">+ * =
are met:<br></div><div dir=3D"ltr">+ * 1. Redistributions of source code mu=
st retain the above copyright<br></div><div dir=3D"ltr">+ *&nbsp; &nbsp; no=
tice, this list of conditions and the following disclaimer.<br></div><div d=
ir=3D"ltr">+ * 2. Redistributions in binary form must reproduce the above c=
opyright<br></div><div dir=3D"ltr">+ *&nbsp; &nbsp; notice, this list of co=
nditions and the following disclaimer in the<br></div><div dir=3D"ltr">+ *&=
nbsp; &nbsp; documentation and/or other materials provided with the distrib=
ution.<br></div><div dir=3D"ltr">+ *<br></div><div dir=3D"ltr">+ * THIS SOF=
TWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS<br></div>=
<div dir=3D"ltr">+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLU=
DING, BUT NOT LIMITED<br></div><div dir=3D"ltr">+ * TO, THE IMPLIED WARRANT=
IES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR<br></div><div dir=3D"lt=
r">+ * PURPOSE ARE DISCLAIMED.&nbsp; IN NO EVENT SHALL THE FOUNDATION OR CO=
NTRIBUTORS<br></div><div dir=3D"ltr">+ * BE LIABLE FOR ANY DIRECT, INDIRECT=
, INCIDENTAL, SPECIAL, EXEMPLARY, OR<br></div><div dir=3D"ltr">+ * CONSEQUE=
NTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF<br></div><div =
dir=3D"ltr">+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS=
; OR BUSINESS<br></div><div dir=3D"ltr">+ * INTERRUPTION) HOWEVER CAUSED AN=
D ON ANY THEORY OF LIABILITY, WHETHER IN<br></div><div dir=3D"ltr">+ * CONT=
RACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)<br></di=
v><div dir=3D"ltr">+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, =
EVEN IF ADVISED OF THE<br></div><div dir=3D"ltr">+ * POSSIBILITY OF SUCH DA=
MAGE.<br></div><div dir=3D"ltr">+ */<br></div><div dir=3D"ltr">+#include &l=
t;sys/cdefs.h&gt;<br></div><div dir=3D"ltr">+__RCSID("$NetBSD: fgets_chk.c,=
v 1.6 2009/02/05 05:41:51 lukem Exp $");<br></div><div dir=3D"ltr">+<br></d=
iv><div dir=3D"ltr">+#include &lt;limits.h&gt;<br></div><div dir=3D"ltr">+#=
include &lt;stdio.h&gt;<br></div><div dir=3D"ltr">+#include &lt;stdlib.h&gt=
;<br></div><div dir=3D"ltr">+#include &lt;string.h&gt;<br></div><div dir=3D=
"ltr">+<br></div><div dir=3D"ltr">+#include &lt;ssp/stdio.h&gt;<br></div><d=
iv dir=3D"ltr">+#include &lt;ssp/string.h&gt;<br></div><div dir=3D"ltr">+#u=
ndef fgets<br></div><div dir=3D"ltr">+<br></div><div dir=3D"ltr">+char *<br=
></div><div dir=3D"ltr">+__fgets_chk(char * __restrict buf, int len, size_t=
 slen, FILE *fp)<br></div><div dir=3D"ltr">+{<br></div><div dir=3D"ltr">+&n=
bsp;&nbsp;&nbsp; if (slen &gt;=3D (size_t)INT_MAX)<br></div><div dir=3D"ltr=
">+&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; return (fgets(buf, len, fp));<br><=
/div><div dir=3D"ltr">+<br></div><div dir=3D"ltr">+&nbsp;&nbsp;&nbsp; if (l=
en &gt;=3D 0 &amp;&amp; (size_t)len &gt; slen)<br></div><div dir=3D"ltr">+&=
nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; __chk_fail();<br></div><div dir=3D"ltr=
">+<br></div><div dir=3D"ltr">+&nbsp;&nbsp;&nbsp; return (fgets(buf, len, f=
p));<br></div><div dir=3D"ltr">+}<br></div><div dir=3D"ltr">diff --git a/li=
b/libc/secure/gets_chk.c b/lib/libc/secure/gets_chk.c<br></div><div dir=3D"=
ltr">new file mode 100644<br></div><div dir=3D"ltr">index 000000000000..18c=
1e2d18f43<br></div><div dir=3D"ltr">--- /dev/null<br></div><div dir=3D"ltr"=
>+++ b/lib/libc/secure/gets_chk.c<br></div><div dir=3D"ltr">@@ -0,0 +1,74 @=
@<br></div><div dir=3D"ltr">+/*-<br></div><div dir=3D"ltr">+ *<br></div><di=
v dir=3D"ltr">+ * SPDX-License-Identifier: BSD-2-Clause<br></div><div dir=
=3D"ltr">+ *<br></div><div dir=3D"ltr">+ * Copyright (c) 2006 The NetBSD Fo=
undation, Inc.<br></div><div dir=3D"ltr">+ * All rights reserved.<br></div>=
<div dir=3D"ltr">+ *<br></div><div dir=3D"ltr">+ * This code is derived fro=
m software contributed to The NetBSD Foundation<br></div><div dir=3D"ltr">+=
 * by Christos Zoulas.<br></div><div dir=3D"ltr">+ *<br></div><div dir=3D"l=
tr">+ * Redistribution and use in source and binary forms, with or without<=
br></div><div dir=3D"ltr">+ * modification, are permitted provided that the=
 following conditions<br></div><div dir=3D"ltr">+ * are met:<br></div><div =
dir=3D"ltr">+ * 1. Redistributions of source code must retain the above cop=
yright<br></div><div dir=3D"ltr">+ *&nbsp; &nbsp; notice, this list of cond=
itions and the following disclaimer.<br></div><div dir=3D"ltr">+ * 2. Redis=
tributions in binary form must reproduce the above copyright<br></div><div =
dir=3D"ltr">+ *&nbsp; &nbsp; notice, this list of conditions and the follow=
ing disclaimer in the<br></div><div dir=3D"ltr">+ *&nbsp; &nbsp; documentat=
ion and/or other materials provided with the distribution.<br></div><div di=
r=3D"ltr">+ *<br></div><div dir=3D"ltr">+ * THIS SOFTWARE IS PROVIDED BY TH=
E NETBSD FOUNDATION, INC. AND CONTRIBUTORS<br></div><div dir=3D"ltr">+ * ``=
AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED<b=
r></div><div dir=3D"ltr">+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY =
AND FITNESS FOR A PARTICULAR<br></div><div dir=3D"ltr">+ * PURPOSE ARE DISC=
LAIMED.&nbsp; IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS<br></div><di=
v dir=3D"ltr">+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, =
EXEMPLARY, OR<br></div><div dir=3D"ltr">+ * CONSEQUENTIAL DAMAGES (INCLUDIN=
G, BUT NOT LIMITED TO, PROCUREMENT OF<br></div><div dir=3D"ltr">+ * SUBSTIT=
UTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS<br></div>=
<div dir=3D"ltr">+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIAB=
ILITY, WHETHER IN<br></div><div dir=3D"ltr">+ * CONTRACT, STRICT LIABILITY,=
 OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)<br></div><div dir=3D"ltr">+ * =
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE<=
br></div><div dir=3D"ltr">+ * POSSIBILITY OF SUCH DAMAGE.<br></div><div dir=
=3D"ltr">+ */<br></div><div dir=3D"ltr">+#include &lt;sys/cdefs.h&gt;<br></=
div><div dir=3D"ltr">+__RCSID("$NetBSD: gets_chk.c,v 1.7 2013/10/04 20:49:1=
6 christos Exp $");<br></div><div dir=3D"ltr">+<br></div><div dir=3D"ltr">+=
#include &lt;limits.h&gt;<br></div><div dir=3D"ltr">+#include &lt;stdio.h&g=
t;<br></div><div dir=3D"ltr">+#include &lt;stdlib.h&gt;<br></div><div dir=
=3D"ltr">+#include &lt;string.h&gt;<br></div><div dir=3D"ltr">+<br></div><d=
iv dir=3D"ltr">+#include &lt;ssp/stdio.h&gt;<br></div><div dir=3D"ltr">+#in=
clude &lt;ssp/string.h&gt;<br></div><div dir=3D"ltr">+<br></div><div dir=3D=
"ltr">+char *__gets_unsafe(char *);<br></div><div dir=3D"ltr">+<br></div><d=
iv dir=3D"ltr">+char *<br></div><div dir=3D"ltr">+__gets_chk(char * __restr=
ict buf, size_t slen)<br></div><div dir=3D"ltr">+{<br></div><div dir=3D"ltr=
">+&nbsp;&nbsp;&nbsp; char *abuf;<br></div><div dir=3D"ltr">+&nbsp;&nbsp;&n=
bsp; size_t len;<br></div><div dir=3D"ltr">+<br></div><div dir=3D"ltr">+&nb=
sp;&nbsp;&nbsp; if (slen &gt;=3D (size_t)INT_MAX)<br></div><div dir=3D"ltr"=
>+&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; return (__gets_unsafe(buf));<br></d=
iv><div dir=3D"ltr">+<br></div><div dir=3D"ltr">+&nbsp;&nbsp;&nbsp; if ((ab=
uf =3D malloc(slen + 1)) =3D=3D NULL)<br></div><div dir=3D"ltr">+&nbsp;&nbs=
p;&nbsp; &nbsp;&nbsp;&nbsp; return (__gets_unsafe(buf));<br></div><div dir=
=3D"ltr">+<br></div><div dir=3D"ltr">+&nbsp;&nbsp;&nbsp; if (fgets(abuf, (i=
nt)(slen + 1), stdin) =3D=3D NULL) {<br></div><div dir=3D"ltr">+&nbsp;&nbsp=
;&nbsp; &nbsp;&nbsp;&nbsp; free(abuf);<br></div><div dir=3D"ltr">+&nbsp;&nb=
sp;&nbsp; &nbsp;&nbsp;&nbsp; return (NULL);<br></div><div dir=3D"ltr">+&nbs=
p;&nbsp;&nbsp; }<br></div><div dir=3D"ltr">+<br></div><div dir=3D"ltr">+&nb=
sp;&nbsp;&nbsp; len =3D strlen(abuf);<br></div><div dir=3D"ltr">+&nbsp;&nbs=
p;&nbsp; if (len &gt; 0 &amp;&amp; abuf[len - 1] =3D=3D '\n')<br></div><div=
 dir=3D"ltr">+&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; --len;<br></div><div di=
r=3D"ltr">+<br></div><div dir=3D"ltr">+&nbsp;&nbsp;&nbsp; if (len &gt;=3D s=
len)<br></div><div dir=3D"ltr">+&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; __chk=
_fail();<br></div><div dir=3D"ltr">+<br></div><div dir=3D"ltr">+&nbsp;&nbsp=
;&nbsp; (void)memcpy(buf, abuf, len);<br></div><div dir=3D"ltr">+<br></div>=
<div dir=3D"ltr">+&nbsp;&nbsp;&nbsp; buf[len] =3D '\0';<br></div><div dir=
=3D"ltr">+&nbsp;&nbsp;&nbsp; free(abuf);<br></div><div dir=3D"ltr">+&nbsp;&=
nbsp;&nbsp; return (buf);<br></div><div dir=3D"ltr">+}<br></div><div dir=3D=
"ltr">diff --git a/lib/libc/secure/memcpy_chk.c b/lib/libc/secure/memcpy_ch=
k.c<br></div><div dir=3D"ltr">new file mode 100644<br></div><div dir=3D"ltr=
">index 000000000000..99cf2d5f13ff<br></div><div dir=3D"ltr">--- /dev/null<=
br></div><div dir=3D"ltr">+++ b/lib/libc/secure/memcpy_chk.c<br></div><div =
dir=3D"ltr">@@ -0,0 +1,53 @@<br></div><div dir=3D"ltr">+/*-<br></div><div d=
ir=3D"ltr">+ *<br></div><div dir=3D"ltr">+ * SPDX-License-Identifier: BSD-2=
-Clause<br></div><div dir=3D"ltr">+ *<br></div><div dir=3D"ltr">+ * Copyrig=
ht (c) 2006 The NetBSD Foundation, Inc.<br></div><div dir=3D"ltr">+ * All r=
ights reserved.<br></div><div dir=3D"ltr">+ *<br></div><div dir=3D"ltr">+ *=
 This code is derived from software contributed to The NetBSD Foundation<br=
></div><div dir=3D"ltr">+ * by Christos Zoulas.<br></div><div dir=3D"ltr">+=
 *<br></div><div dir=3D"ltr">+ * Redistribution and use in source and binar=
y forms, with or without<br></div><div dir=3D"ltr">+ * modification, are pe=
rmitted provided that the following conditions<br></div><div dir=3D"ltr">+ =
* are met:<br></div><div dir=3D"ltr">+ * 1. Redistributions of source code =
must retain the above copyright<br></div><div dir=3D"ltr">+ *&nbsp; &nbsp; =
notice, this list of conditions and the following disclaimer.<br></div><div=
 dir=3D"ltr">+ * 2. Redistributions in binary form must reproduce the above=
 copyright<br></div><div dir=3D"ltr">+ *&nbsp; &nbsp; notice, this list of =
conditions and the following disclaimer in the<br></div><div dir=3D"ltr">+ =
*&nbsp; &nbsp; documentation and/or other materials provided with the distr=
ibution.<br></div><div dir=3D"ltr">+ *<br></div><div dir=3D"ltr">+ * THIS S=
OFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS<br></di=
v><div dir=3D"ltr">+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INC=
LUDING, BUT NOT LIMITED<br></div><div dir=3D"ltr">+ * TO, THE IMPLIED WARRA=
NTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR<br></div><div dir=3D"=
ltr">+ * PURPOSE ARE DISCLAIMED.&nbsp; IN NO EVENT SHALL THE FOUNDATION OR =
CONTRIBUTORS<br></div><div dir=3D"ltr">+ * BE LIABLE FOR ANY DIRECT, INDIRE=
CT, INCIDENTAL, SPECIAL, EXEMPLARY, OR<br></div><div dir=3D"ltr">+ * CONSEQ=
UENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF<br></div><di=
v dir=3D"ltr">+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFI=
TS; OR BUSINESS<br></div><div dir=3D"ltr">+ * INTERRUPTION) HOWEVER CAUSED =
AND ON ANY THEORY OF LIABILITY, WHETHER IN<br></div><div dir=3D"ltr">+ * CO=
NTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)<br></=
div><div dir=3D"ltr">+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE=
, EVEN IF ADVISED OF THE<br></div><div dir=3D"ltr">+ * POSSIBILITY OF SUCH =
DAMAGE.<br></div><div dir=3D"ltr">+ */<br></div><div dir=3D"ltr">+#include =
&lt;sys/cdefs.h&gt;<br></div><div dir=3D"ltr">+__RCSID("$NetBSD: memcpy_chk=
.c,v 1.7 2015/05/13 19:57:16 joerg Exp $");<br></div><div dir=3D"ltr">+<br>=
</div><div dir=3D"ltr">+#include &lt;string.h&gt;<br></div><div dir=3D"ltr"=
>+<br></div><div dir=3D"ltr">+#include &lt;ssp/string.h&gt;<br></div><div d=
ir=3D"ltr">+#undef memcpy<br></div><div dir=3D"ltr">+<br></div><div dir=3D"=
ltr">+#include "ssp_internal.h"<br></div><div dir=3D"ltr">+<br></div><div d=
ir=3D"ltr">+void *<br></div><div dir=3D"ltr">+__memcpy_chk(void * __restric=
t dst, const void * __restrict src, size_t len,<br></div><div dir=3D"ltr">+=
&nbsp; &nbsp; size_t slen)<br></div><div dir=3D"ltr">+{<br></div><div dir=
=3D"ltr">+&nbsp;&nbsp;&nbsp; if (len &gt; slen)<br></div><div dir=3D"ltr">+=
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; __chk_fail();<br></div><div dir=3D"lt=
r">+<br></div><div dir=3D"ltr">+&nbsp;&nbsp;&nbsp; if (__ssp_overlap((const=
 char *)src, (const char *)dst, len))<br></div><div dir=3D"ltr">+&nbsp;&nbs=
p;&nbsp; &nbsp;&nbsp;&nbsp; __chk_fail();<br></div><div dir=3D"ltr">+<br></=
div><div dir=3D"ltr">+&nbsp;&nbsp;&nbsp; return (memcpy(dst, src, len));<br=
></div><div dir=3D"ltr">+}<br></div><div dir=3D"ltr">diff --git a/lib/libc/=
secure/memmove_chk.c b/lib/libc/secure/memmove_chk.c<br></div><div dir=3D"l=
tr">new file mode 100644<br></div><div dir=3D"ltr">index 000000000000..07f9=
65d608fc<br></div><div dir=3D"ltr">--- /dev/null<br></div><div dir=3D"ltr">=
+++ b/lib/libc/secure/memmove_chk.c<br></div><div dir=3D"ltr">@@ -0,0 +1,47=
 @@<br></div><div dir=3D"ltr">+/*-<br></div><div dir=3D"ltr">+ *<br></div><=
div dir=3D"ltr">+ * SPDX-License-Identifier: BSD-2-Clause<br></div><div dir=
=3D"ltr">+ *<br></div><div dir=3D"ltr">+ * Copyright (c) 2006 The NetBSD Fo=
undation, Inc.<br></div><div dir=3D"ltr">+ * All rights reserved.<br></div>=
<div dir=3D"ltr">+ *<br></div><div dir=3D"ltr">+ * This code is derived fro=
m software contributed to The NetBSD Foundation<br></div><div dir=3D"ltr">+=
 * by Christos Zoulas.<br></div><div dir=3D"ltr">+ *<br></div><div dir=3D"l=
tr">+ * Redistribution and use in source and binary forms, with or without<=
br></div><div dir=3D"ltr">+ * modification, are permitted provided that the=
 following conditions<br></div><div dir=3D"ltr">+ * are met:<br></div><div =
dir=3D"ltr">+ * 1. Redistributions of source code must retain the above cop=
yright<br></div><div dir=3D"ltr">+ *&nbsp; &nbsp; notice, this list of cond=
itions and the following disclaimer.<br></div><div dir=3D"ltr">+ * 2. Redis=
tributions in binary form must reproduce the above copyright<br></div><div =
dir=3D"ltr">+ *&nbsp; &nbsp; notice, this list of conditions and the follow=
ing disclaimer in the<br></div><div dir=3D"ltr">+ *&nbsp; &nbsp; documentat=
ion and/or other materials provided with the distribution.<br></div><div di=
r=3D"ltr">+ *<br></div><div dir=3D"ltr">+ * THIS SOFTWARE IS PROVIDED BY TH=
E NETBSD FOUNDATION, INC. AND CONTRIBUTORS<br></div><div dir=3D"ltr">+ * ``=
AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED<b=
r></div><div dir=3D"ltr">+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY =
AND FITNESS FOR A PARTICULAR<br></div><div dir=3D"ltr">+ * PURPOSE ARE DISC=
LAIMED.&nbsp; IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS<br></div><di=
v dir=3D"ltr">+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, =
EXEMPLARY, OR<br></div><div dir=3D"ltr">+ * CONSEQUENTIAL DAMAGES (INCLUDIN=
G, BUT NOT LIMITED TO, PROCUREMENT OF<br></div><div dir=3D"ltr">+ * SUBSTIT=
UTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS<br></div>=
<div dir=3D"ltr">+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIAB=
ILITY, WHETHER IN<br></div><div dir=3D"ltr">+ * CONTRACT, STRICT LIABILITY,=
 OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)<br></div><div dir=3D"ltr">+ * =
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE<=
br></div><div dir=3D"ltr">+ * POSSIBILITY OF SUCH DAMAGE.<br></div><div dir=
=3D"ltr">+ */<br></div><div dir=3D"ltr">+#include &lt;sys/cdefs.h&gt;<br></=
div><div dir=3D"ltr">+__RCSID("$NetBSD: memmove_chk.c,v 1.6 2020/09/05 13:3=
7:59 mrg Exp $");<br></div><div dir=3D"ltr">+<br></div><div dir=3D"ltr">+#i=
nclude &lt;string.h&gt;<br></div><div dir=3D"ltr">+<br></div><div dir=3D"lt=
r">+#include &lt;ssp/string.h&gt;<br></div><div dir=3D"ltr">+#undef memmove=
<br></div><div dir=3D"ltr">+<br></div><div dir=3D"ltr">+void *<br></div><di=
v dir=3D"ltr">+__memmove_chk(void *dst, const void *src, size_t len,<br></d=
iv><div dir=3D"ltr">+&nbsp; &nbsp; size_t slen)<br></div><div dir=3D"ltr">+=
{<br></div><div dir=3D"ltr">+&nbsp;&nbsp;&nbsp; if (len &gt; slen)<br></div=
><div dir=3D"ltr">+&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; __chk_fail();<br><=
/div><div dir=3D"ltr">+&nbsp;&nbsp;&nbsp; return (memmove(dst, src, len));<=
br></div><div dir=3D"ltr">+}<br></div><div dir=3D"ltr">diff --git a/lib/lib=
c/secure/memset_chk.c b/lib/libc/secure/memset_chk.c<br></div><div dir=3D"l=
tr">new file mode 100644<br></div><div dir=3D"ltr">index 000000000000..f337=
be98b46d<br></div><div dir=3D"ltr">--- /dev/null<br></div><div dir=3D"ltr">=
+++ b/lib/libc/secure/memset_chk.c<br></div><div dir=3D"ltr">@@ -0,0 +1,46 =
@@<br></div><div dir=3D"ltr">+/*-<br></div><div dir=3D"ltr">+ *<br></div><d=
iv dir=3D"ltr">+ * SPDX-License-Identifier: BSD-2-Clause<br></div><div dir=
=3D"ltr">+ *<br></div><div dir=3D"ltr">+ * Copyright (c) 2006 The NetBSD Fo=
undation, Inc.<br></div><div dir=3D"ltr">+ * All rights reserved.<br></div>=
<div dir=3D"ltr">+ *<br></div><div dir=3D"ltr">+ * This code is derived fro=
m software contributed to The NetBSD Foundation<br></div><div dir=3D"ltr">+=
 * by Christos Zoulas.<br></div><div dir=3D"ltr">+ *<br></div><div dir=3D"l=
tr">+ * Redistribution and use in source and binary forms, with or without<=
br></div><div dir=3D"ltr">+ * modification, are permitted provided that the=
 following conditions<br></div><div dir=3D"ltr">+ * are met:<br></div><div =
dir=3D"ltr">+ * 1. Redistributions of source code must retain the above cop=
yright<br></div><div dir=3D"ltr">+ *&nbsp; &nbsp; notice, this list of cond=
itions and the following disclaimer.<br></div><div dir=3D"ltr">+ * 2. Redis=
tributions in binary form must reproduce the above copyright<br></div><div =
dir=3D"ltr">+ *&nbsp; &nbsp; notice, this list of conditions and the follow=
ing disclaimer in the<br></div><div dir=3D"ltr">+ *&nbsp; &nbsp; documentat=
ion and/or other materials provided with the distribution.<br></div><div di=
r=3D"ltr">+ *<br></div><div dir=3D"ltr">+ * THIS SOFTWARE IS PROVIDED BY TH=
E NETBSD FOUNDATION, INC. AND CONTRIBUTORS<br></div><div dir=3D"ltr">+ * ``=
AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED<b=
r></div><div dir=3D"ltr">+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY =
AND FITNESS FOR A PARTICULAR<br></div><div dir=3D"ltr">+ * PURPOSE ARE DISC=
LAIMED.&nbsp; IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS<br></div><di=
v dir=3D"ltr">+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, =
EXEMPLARY, OR<br></div><div dir=3D"ltr">+ * CONSEQUENTIAL DAMAGES (INCLUDIN=
G, BUT NOT LIMITED TO, PROCUREMENT OF<br></div><div dir=3D"ltr">+ * SUBSTIT=
UTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS<br></div>=
<div dir=3D"ltr">+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIAB=
ILITY, WHETHER IN<br></div><div dir=3D"ltr">+ * CONTRACT, STRICT LIABILITY,=
 OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)<br></div><div dir=3D"ltr">+ * =
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE<=
br></div><div dir=3D"ltr">+ * POSSIBILITY OF SUCH DAMAGE.<br></div><div dir=
=3D"ltr">+ */<br></div><div dir=3D"ltr">+#include &lt;sys/cdefs.h&gt;<br></=
div><div dir=3D"ltr">+__RCSID("$NetBSD: memset_chk.c,v 1.5 2014/09/17 00:39=
:28 joerg Exp $");<br></div><div dir=3D"ltr">+<br></div><div dir=3D"ltr">+#=
include &lt;string.h&gt;<br></div><div dir=3D"ltr">+<br></div><div dir=3D"l=
tr">+#include &lt;ssp/string.h&gt;<br></div><div dir=3D"ltr">+#undef memset=
<br></div><div dir=3D"ltr">+<br></div><div dir=3D"ltr">+void *<br></div><di=
v dir=3D"ltr">+__memset_chk(void * __restrict dst, int val, size_t len, siz=
e_t slen)<br></div><div dir=3D"ltr">+{<br></div><div dir=3D"ltr">+&nbsp;&nb=
sp;&nbsp; if (len &gt; slen)<br></div><div dir=3D"ltr">+&nbsp;&nbsp;&nbsp; =
&nbsp;&nbsp;&nbsp; __chk_fail();<br></div><div dir=3D"ltr">+&nbsp;&nbsp;&nb=
sp; return (memset(dst, val, len));<br></div><div dir=3D"ltr">+}<br></div><=
div dir=3D"ltr">diff --git a/lib/libc/secure/snprintf_chk.c b/lib/libc/secu=
re/snprintf_chk.c<br></div><div dir=3D"ltr">new file mode 100644<br></div><=
div dir=3D"ltr">index 000000000000..52ef874ede5b<br></div><div dir=3D"ltr">=
--- /dev/null<br></div><div dir=3D"ltr">+++ b/lib/libc/secure/snprintf_chk.=
c<br></div><div dir=3D"ltr">@@ -0,0 +1,56 @@<br></div><div dir=3D"ltr">+/*-=
<br></div><div dir=3D"ltr">+ *<br></div><div dir=3D"ltr">+ * SPDX-License-I=
dentifier: BSD-2-Clause<br></div><div dir=3D"ltr">+ *<br></div><div dir=3D"=
ltr">+ * Copyright (c) 2006 The NetBSD Foundation, Inc.<br></div><div dir=
=3D"ltr">+ * All rights reserved.<br></div><div dir=3D"ltr">+ *<br></div><d=
iv dir=3D"ltr">+ * This code is derived from software contributed to The Ne=
tBSD Foundation<br></div><div dir=3D"ltr">+ * by Christos Zoulas.<br></div>=
<div dir=3D"ltr">+ *<br></div><div dir=3D"ltr">+ * Redistribution and use i=
n source and binary forms, with or without<br></div><div dir=3D"ltr">+ * mo=
dification, are permitted provided that the following conditions<br></div><=
div dir=3D"ltr">+ * are met:<br></div><div dir=3D"ltr">+ * 1. Redistributio=
ns of source code must retain the above copyright<br></div><div dir=3D"ltr"=
>+ *&nbsp; &nbsp; notice, this list of conditions and the following disclai=
mer.<br></div><div dir=3D"ltr">+ * 2. Redistributions in binary form must r=
eproduce the above copyright<br></div><div dir=3D"ltr">+ *&nbsp; &nbsp; not=
ice, this list of conditions and the following disclaimer in the<br></div><=
div dir=3D"ltr">+ *&nbsp; &nbsp; documentation and/or other materials provi=
ded with the distribution.<br></div><div dir=3D"ltr">+ *<br></div><div dir=
=3D"ltr">+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND C=
ONTRIBUTORS<br></div><div dir=3D"ltr">+ * ``AS IS'' AND ANY EXPRESS OR IMPL=
IED WARRANTIES, INCLUDING, BUT NOT LIMITED<br></div><div dir=3D"ltr">+ * TO=
, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR<br=
></div><div dir=3D"ltr">+ * PURPOSE ARE DISCLAIMED.&nbsp; IN NO EVENT SHALL=
 THE FOUNDATION OR CONTRIBUTORS<br></div><div dir=3D"ltr">+ * BE LIABLE FOR=
 ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR<br></div><div dir=
=3D"ltr">+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREM=
ENT OF<br></div><div dir=3D"ltr">+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF =
USE, DATA, OR PROFITS; OR BUSINESS<br></div><div dir=3D"ltr">+ * INTERRUPTI=
ON) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN<br></div><div=
 dir=3D"ltr">+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE =
OR OTHERWISE)<br></div><div dir=3D"ltr">+ * ARISING IN ANY WAY OUT OF THE U=
SE OF THIS SOFTWARE, EVEN IF ADVISED OF THE<br></div><div dir=3D"ltr">+ * P=
OSSIBILITY OF SUCH DAMAGE.<br></div><div dir=3D"ltr">+ */<br></div><div dir=
=3D"ltr">+#include &lt;sys/cdefs.h&gt;<br></div><div dir=3D"ltr">+__RCSID("=
$NetBSD: snprintf_chk.c,v 1.5 2008/04/28 20:23:00 martin Exp $");<br></div>=
<div dir=3D"ltr">+<br></div><div dir=3D"ltr">+#include &lt;stdarg.h&gt;<br>=
</div><div dir=3D"ltr">+#include &lt;stdio.h&gt;<br></div><div dir=3D"ltr">=
+<br></div><div dir=3D"ltr">+#include &lt;ssp/stdio.h&gt;<br></div><div dir=
=3D"ltr">+#undef vsnprintf<br></div><div dir=3D"ltr">+<br></div><div dir=3D=
"ltr">+int<br></div><div dir=3D"ltr">+__snprintf_chk(char * __restrict buf,=
 size_t len, int flags, size_t slen,<br></div><div dir=3D"ltr">+&nbsp; &nbs=
p; const char * __restrict fmt, ...)<br></div><div dir=3D"ltr">+{<br></div>=
<div dir=3D"ltr">+&nbsp;&nbsp;&nbsp; va_list ap;<br></div><div dir=3D"ltr">=
+&nbsp;&nbsp;&nbsp; int rv;<br></div><div dir=3D"ltr">+<br></div><div dir=
=3D"ltr">+&nbsp;&nbsp;&nbsp; if (len &gt; slen)<br></div><div dir=3D"ltr">+=
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; __chk_fail();<br></div><div dir=3D"lt=
r">+<br></div><div dir=3D"ltr">+&nbsp;&nbsp;&nbsp; va_start(ap, fmt);<br></=
div><div dir=3D"ltr">+&nbsp;&nbsp;&nbsp; rv =3D vsnprintf(buf, len, fmt, ap=
);<br></div><div dir=3D"ltr">+&nbsp;&nbsp;&nbsp; va_end(ap);<br></div><div =
dir=3D"ltr">+<br></div><div dir=3D"ltr">+&nbsp;&nbsp;&nbsp; return (rv);<br=
></div><div dir=3D"ltr">+}<br></div><div dir=3D"ltr">diff --git a/lib/libc/=
secure/sprintf_chk.c b/lib/libc/secure/sprintf_chk.c<br></div><div dir=3D"l=
tr">new file mode 100644<br></div><div dir=3D"ltr">index 000000000000..d4c4=
2ccba3ce<br></div><div dir=3D"ltr">--- /dev/null<br></div><div dir=3D"ltr">=
+++ b/lib/libc/secure/sprintf_chk.c<br></div><div dir=3D"ltr">@@ -0,0 +1,61=
 @@<br></div><div dir=3D"ltr">+/*-<br></div><div dir=3D"ltr">+ *<br></div><=
div dir=3D"ltr">+ * SPDX-License-Identifier: BSD-2-Clause<br></div><div dir=
=3D"ltr">+ *<br></div><div dir=3D"ltr">+ * Copyright (c) 2006 The NetBSD Fo=
undation, Inc.<br></div><div dir=3D"ltr">+ * All rights reserved.<br></div>=
<div dir=3D"ltr">+ *<br></div><div dir=3D"ltr">+ * This code is derived fro=
m software contributed to The NetBSD Foundation<br></div><div dir=3D"ltr">*=
** 1063 LINES SKIPPED ***<br></div></div>
            </div>
        </div></body></html>
------=_Part_1587021_1250298158.1716057759643--



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?177052019.1587022.1716057759658>