diff --git a/include/ssp/Makefile b/include/ssp/Makefile --- a/include/ssp/Makefile +++ b/include/ssp/Makefile @@ -1,4 +1,4 @@ -INCS= poll.h ssp.h stdio.h stdlib.h string.h strings.h unistd.h +INCS= poll.h ssp.h stdio.h stdlib.h string.h strings.h unistd.h wchar.h INCSDIR= ${INCLUDEDIR}/ssp .include diff --git a/include/ssp/wchar.h b/include/ssp/wchar.h new file mode 100644 --- /dev/null +++ b/include/ssp/wchar.h @@ -0,0 +1,229 @@ +/*- + * SPDX-License-Identifier: BSD-2-Clause + * + * Copyright (c) 2024, Klara, Inc. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ +#ifndef _SSP_WCHAR_H_ +#define _SSP_WCHAR_H_ + +#include + +#if __SSP_FORTIFY_LEVEL > 0 + +static inline int +__ssp_wchar_overlap(const void *leftp, const void *rightp, size_t len) +{ + + if (len > SIZE_MAX / sizeof(wchar_t)) + return (1); + return (__ssp_overlap(leftp, rightp, len * sizeof(wchar_t))); +} + +/* + * __ssp_wbos for w*() calls where the size parameters are in sizeof(wchar_t) + * units, so the result needs to be scaled appropriately. + */ +__ssp_inline size_t +__ssp_wbos(void *ptr) +{ + const size_t ptrsize = __ssp_bos(ptr); + + if (ptrsize == (size_t)-1) + return (ptrsize); + + return (ptrsize / sizeof(wchar_t)); +} + +__BEGIN_DECLS +__ssp_redirect_raw_impl(wchar_t *, wmemcpy, wmemcpy, + (wchar_t *__restrict buf, const wchar_t *__restrict src, size_t len)) +{ + const size_t slen = __ssp_wbos(buf); + + if (len > slen) + __chk_fail(); + if (__ssp_wchar_overlap(src, buf, len)) + __chk_fail(); + + return (__ssp_real(wmemcpy)(buf, src, len)); +} + +__ssp_redirect_raw_impl(wchar_t *, wmempcpy, wmempcpy, + (wchar_t *__restrict buf, const wchar_t *__restrict src, size_t len)) +{ + const size_t slen = __ssp_wbos(buf); + + if (len > slen) + __chk_fail(); + if (__ssp_wchar_overlap(src, buf, len)) + __chk_fail(); + + return (__ssp_real(wmempcpy)(buf, src, len)); +} + +__ssp_redirect_raw_impl(wchar_t *, wmemmove, wmemmove, + (wchar_t *buf, const wchar_t *src, size_t len)) +{ + const size_t slen = __ssp_wbos(buf); + + if (len > slen) + __chk_fail(); + + return (__ssp_real(wmemmove)(buf, src, len)); +} + +__ssp_redirect_raw_impl(wchar_t *, wmemset, wmemset, + (wchar_t *buf, wchar_t c, size_t len)) +{ + const size_t slen = __ssp_wbos(buf); + + if (len > slen) + __chk_fail(); + return (__ssp_real(wmemset)(buf, c, len)); +} + +__ssp_redirect_raw_impl(wchar_t *, wcpcpy, wcpcpy, + (wchar_t *__restrict buf, const wchar_t *__restrict src)) +{ + const size_t slen = __ssp_wbos(buf); + const size_t len = wcslen(src); + + if (len >= slen) + __chk_fail(); + if (__ssp_wchar_overlap(buf, src, len)) + __chk_fail(); + + (void)__ssp_real(wmemcpy)(buf, src, len + 1); + return (buf + len); +} + +__ssp_redirect_raw_impl(wchar_t *, wcpncpy, wcpncpy, + (wchar_t *__restrict buf, const wchar_t *__restrict src, size_t len)) +{ + const size_t slen = __ssp_wbos(buf); + + if (len > slen) + __chk_fail(); + if (__ssp_wchar_overlap(buf, src, len)) + __chk_fail(); + + return (__ssp_real(wcpncpy)(buf, src, len)); +} + +__ssp_redirect_raw_impl(wchar_t *, wcscat, wcscat, + (wchar_t *__restrict buf, const wchar_t *__restrict src)) +{ + size_t slen = __ssp_wbos(buf); + wchar_t *cp; + + cp = buf; + while (*cp != L'\0') { + cp++; + if (slen-- == 0) + __chk_fail(); + } + + while (*src != L'\0') { + if (slen-- == 0) + __chk_fail(); + *cp++ = *src++; + } + + if (slen-- == 0) + __chk_fail(); + *cp = '\0'; + return (buf); +} + +__ssp_redirect_raw_impl(wchar_t *, wcscpy, wcscpy, + (wchar_t *__restrict buf, const wchar_t *__restrict src)) +{ + const size_t slen = __ssp_wbos(buf); + size_t len = wcslen(src) + 1; + + if (len > slen) + __chk_fail(); + if (__ssp_wchar_overlap(buf, src, len)) + __chk_fail(); + + return (__ssp_real(wmemcpy)(buf, src, len)); +} + +__ssp_redirect_raw_impl(wchar_t *, wcsncat, wcsncat, + (wchar_t *__restrict buf, const wchar_t *__restrict src, size_t len)) +{ + const size_t slen = __ssp_wbos(buf); + + if (len == 0) + return (buf); + if (len > slen) + __chk_fail(); + if (__ssp_wchar_overlap(buf, src, len)) + __chk_fail(); + + return (__ssp_real(wcsncat)(buf, src, len)); +} + +__ssp_redirect_raw_impl(size_t, wcslcat, wcslcat, + (wchar_t *__restrict buf, const wchar_t *__restrict src, size_t len)) +{ + const size_t slen = __ssp_wbos(buf); + + if (len > slen) + __chk_fail(); + if (__ssp_wchar_overlap(buf, src, len)) + __chk_fail(); + + return (__ssp_real(wcslcat)(buf, src, len)); +} + +__ssp_redirect_raw_impl(wchar_t *, wcsncpy, wcsncpy, + (wchar_t *__restrict buf, const wchar_t *__restrict src, size_t len)) +{ + const size_t slen = __ssp_wbos(buf); + + if (len > slen) + __chk_fail(); + if (__ssp_wchar_overlap(buf, src, len)) + __chk_fail(); + + return (__ssp_real(wcsncpy)(buf, src, len)); +} + +__ssp_redirect_raw_impl(size_t, wcslcpy, wcslcpy, + (wchar_t *__restrict buf, const wchar_t *__restrict src, size_t len)) +{ + const size_t slen = __ssp_wbos(buf); + + if (len > slen) + __chk_fail(); + if (__ssp_wchar_overlap(buf, src, len)) + __chk_fail(); + + return (__ssp_real(wcslcpy)(buf, src, len)); +} +__END_DECLS + +#endif /* __SSP_FORTIFY_LEVEL > 0 */ +#endif /* _SSP_WCHAR_H_ */ diff --git a/include/wchar.h b/include/wchar.h --- a/include/wchar.h +++ b/include/wchar.h @@ -108,6 +108,14 @@ #endif struct tm; +__BEGIN_DECLS +size_t wcslen(const wchar_t *) __pure; +__END_DECLS + +#if !defined(_STANDALONE) && defined(_FORTIFY_SOURCE) && _FORTIFY_SOURCE > 0 +#include +#endif + __BEGIN_DECLS wint_t btowc(int); wint_t fgetwc(FILE *); @@ -146,7 +154,6 @@ size_t wcscspn(const wchar_t *, const wchar_t *) __pure; size_t wcsftime(wchar_t * __restrict, size_t, const wchar_t * __restrict, const struct tm * __restrict); -size_t wcslen(const wchar_t *) __pure; wchar_t *wcsncat(wchar_t * __restrict, const wchar_t * __restrict, size_t); int wcsncmp(const wchar_t *, const wchar_t *, size_t) __pure; diff --git a/lib/libc/string/wcpcpy.c b/lib/libc/string/wcpcpy.c --- a/lib/libc/string/wcpcpy.c +++ b/lib/libc/string/wcpcpy.c @@ -32,9 +32,10 @@ */ #include +#include wchar_t * -wcpcpy(wchar_t * __restrict to, const wchar_t * __restrict from) +__ssp_real(wcpcpy)(wchar_t * __restrict to, const wchar_t * __restrict from) { for (; (*to = *from); ++from, ++to); diff --git a/lib/libc/string/wcpncpy.c b/lib/libc/string/wcpncpy.c --- a/lib/libc/string/wcpncpy.c +++ b/lib/libc/string/wcpncpy.c @@ -27,9 +27,11 @@ */ #include +#include wchar_t * -wcpncpy(wchar_t * __restrict dst, const wchar_t * __restrict src, size_t n) +__ssp_real(wcpncpy)(wchar_t * __restrict dst, const wchar_t * __restrict src, + size_t n) { for (; n--; dst++, src++) { diff --git a/lib/libc/string/wcscat.c b/lib/libc/string/wcscat.c --- a/lib/libc/string/wcscat.c +++ b/lib/libc/string/wcscat.c @@ -35,9 +35,10 @@ #endif /* LIBC_SCCS and not lint */ #endif #include +#include wchar_t * -wcscat(wchar_t * __restrict s1, const wchar_t * __restrict s2) +__ssp_real(wcscat)(wchar_t * __restrict s1, const wchar_t * __restrict s2) { wchar_t *cp; diff --git a/lib/libc/string/wcscpy.c b/lib/libc/string/wcscpy.c --- a/lib/libc/string/wcscpy.c +++ b/lib/libc/string/wcscpy.c @@ -35,9 +35,10 @@ #endif /* LIBC_SCCS and not lint */ #endif #include +#include wchar_t * -wcscpy(wchar_t * __restrict s1, const wchar_t * __restrict s2) +__ssp_real(wcscpy)(wchar_t * __restrict s1, const wchar_t * __restrict s2) { wchar_t *cp; diff --git a/lib/libc/string/wcslcat.c b/lib/libc/string/wcslcat.c --- a/lib/libc/string/wcslcat.c +++ b/lib/libc/string/wcslcat.c @@ -37,6 +37,7 @@ #endif #include #include +#include /* * Appends src to string dst of size siz (unlike wcsncat, siz is the @@ -46,7 +47,7 @@ * truncation occurred. */ size_t -wcslcat(wchar_t *dst, const wchar_t *src, size_t siz) +__ssp_real(wcslcat)(wchar_t *dst, const wchar_t *src, size_t siz) { wchar_t *d = dst; const wchar_t *s = src; diff --git a/lib/libc/string/wcslcpy.c b/lib/libc/string/wcslcpy.c --- a/lib/libc/string/wcslcpy.c +++ b/lib/libc/string/wcslcpy.c @@ -37,6 +37,7 @@ #endif #include #include +#include /* * Copy src to string dst of size siz. At most siz-1 characters @@ -44,7 +45,7 @@ * Returns wcslen(src); if retval >= siz, truncation occurred. */ size_t -wcslcpy(wchar_t *dst, const wchar_t *src, size_t siz) +__ssp_real(wcslcpy)(wchar_t *dst, const wchar_t *src, size_t siz) { wchar_t *d = dst; const wchar_t *s = src; diff --git a/lib/libc/string/wcsncat.c b/lib/libc/string/wcsncat.c --- a/lib/libc/string/wcsncat.c +++ b/lib/libc/string/wcsncat.c @@ -35,9 +35,11 @@ #endif /* LIBC_SCCS and not lint */ #endif #include +#include wchar_t * -wcsncat(wchar_t * __restrict s1, const wchar_t * __restrict s2, size_t n) +__ssp_real(wcsncat)(wchar_t * __restrict s1, const wchar_t * __restrict s2, + size_t n) { wchar_t *p; wchar_t *q; diff --git a/lib/libc/string/wcsncpy.c b/lib/libc/string/wcsncpy.c --- a/lib/libc/string/wcsncpy.c +++ b/lib/libc/string/wcsncpy.c @@ -33,13 +33,15 @@ */ #include +#include /* * Copy src to dst, truncating or null-padding to always copy n bytes. * Return dst. */ wchar_t * -wcsncpy(wchar_t * __restrict dst, const wchar_t * __restrict src, size_t n) +__ssp_real(wcsncpy)(wchar_t * __restrict dst, const wchar_t * __restrict src, + size_t n) { if (n != 0) { wchar_t *d = dst; diff --git a/lib/libc/string/wmemcpy.c b/lib/libc/string/wmemcpy.c --- a/lib/libc/string/wmemcpy.c +++ b/lib/libc/string/wmemcpy.c @@ -36,9 +36,11 @@ #endif #include #include +#include wchar_t * -wmemcpy(wchar_t * __restrict d, const wchar_t * __restrict s, size_t n) +__ssp_real(wmemcpy)(wchar_t * __restrict d, const wchar_t * __restrict s, + size_t n) { return (wchar_t *)memcpy(d, s, n * sizeof(wchar_t)); } diff --git a/lib/libc/string/wmemmove.c b/lib/libc/string/wmemmove.c --- a/lib/libc/string/wmemmove.c +++ b/lib/libc/string/wmemmove.c @@ -36,9 +36,10 @@ #endif #include #include +#include wchar_t * -wmemmove(wchar_t *d, const wchar_t *s, size_t n) +__ssp_real(wmemmove)(wchar_t *d, const wchar_t *s, size_t n) { return (wchar_t *)memmove(d, s, n * sizeof(wchar_t)); } diff --git a/lib/libc/string/wmempcpy.c b/lib/libc/string/wmempcpy.c --- a/lib/libc/string/wmempcpy.c +++ b/lib/libc/string/wmempcpy.c @@ -30,9 +30,11 @@ #include #include +#include wchar_t * -wmempcpy(wchar_t *__restrict dst, const wchar_t *__restrict src, size_t len) +__ssp_real(wmempcpy)(wchar_t *__restrict dst, const wchar_t *__restrict src, + size_t len) { return (wmemcpy(dst, src, len) + len); } diff --git a/lib/libc/string/wmemset.c b/lib/libc/string/wmemset.c --- a/lib/libc/string/wmemset.c +++ b/lib/libc/string/wmemset.c @@ -35,9 +35,10 @@ #endif /* LIBC_SCCS and not lint */ #endif #include +#include wchar_t * -wmemset(wchar_t *s, wchar_t c, size_t n) +__ssp_real(wmemset)(wchar_t *s, wchar_t c, size_t n) { size_t i; wchar_t *p; diff --git a/lib/libc/tests/secure/Makefile b/lib/libc/tests/secure/Makefile --- a/lib/libc/tests/secure/Makefile +++ b/lib/libc/tests/secure/Makefile @@ -8,6 +8,7 @@ FORTIFY_TCATS+= string FORTIFY_TCATS+= strings FORTIFY_TCATS+= unistd +FORTIFY_TCATS+= wchar # Manually run after updating the test generator. generate-tests: .PHONY diff --git a/lib/libc/tests/secure/fortify_poll_test.c b/lib/libc/tests/secure/fortify_poll_test.c --- a/lib/libc/tests/secure/fortify_poll_test.c +++ b/lib/libc/tests/secure/fortify_poll_test.c @@ -19,6 +19,7 @@ #include #include #include +#include #include static FILE * __unused diff --git a/lib/libc/tests/secure/fortify_stdio_test.c b/lib/libc/tests/secure/fortify_stdio_test.c --- a/lib/libc/tests/secure/fortify_stdio_test.c +++ b/lib/libc/tests/secure/fortify_stdio_test.c @@ -19,6 +19,7 @@ #include #include #include +#include #include static FILE * __unused diff --git a/lib/libc/tests/secure/fortify_stdlib_test.c b/lib/libc/tests/secure/fortify_stdlib_test.c --- a/lib/libc/tests/secure/fortify_stdlib_test.c +++ b/lib/libc/tests/secure/fortify_stdlib_test.c @@ -19,6 +19,7 @@ #include #include #include +#include #include static FILE * __unused diff --git a/lib/libc/tests/secure/fortify_string_test.c b/lib/libc/tests/secure/fortify_string_test.c --- a/lib/libc/tests/secure/fortify_string_test.c +++ b/lib/libc/tests/secure/fortify_string_test.c @@ -19,6 +19,7 @@ #include #include #include +#include #include static FILE * __unused diff --git a/lib/libc/tests/secure/fortify_strings_test.c b/lib/libc/tests/secure/fortify_strings_test.c --- a/lib/libc/tests/secure/fortify_strings_test.c +++ b/lib/libc/tests/secure/fortify_strings_test.c @@ -19,6 +19,7 @@ #include #include #include +#include #include static FILE * __unused diff --git a/lib/libc/tests/secure/fortify_unistd_test.c b/lib/libc/tests/secure/fortify_unistd_test.c --- a/lib/libc/tests/secure/fortify_unistd_test.c +++ b/lib/libc/tests/secure/fortify_unistd_test.c @@ -19,6 +19,7 @@ #include #include #include +#include #include static FILE * __unused diff --git a/lib/libc/tests/secure/fortify_string_test.c b/lib/libc/tests/secure/fortify_wchar_test.c copy from lib/libc/tests/secure/fortify_string_test.c copy to lib/libc/tests/secure/fortify_wchar_test.c --- a/lib/libc/tests/secure/fortify_string_test.c +++ b/lib/libc/tests/secure/fortify_wchar_test.c @@ -1,4 +1,4 @@ -/* @generated by `generate-fortify-tests.lua "string"` */ +/* @generated by `generate-fortify-tests.lua "wchar"` */ #define _FORTIFY_SOURCE 2 #define TMPFILE_SIZE (1024 * 32) @@ -19,6 +19,7 @@ #include #include #include +#include #include static FILE * __unused @@ -113,93 +114,93 @@ close(fd); } -ATF_TC_WITHOUT_HEAD(memcpy_before_end); -ATF_TC_BODY(memcpy_before_end, tc) +ATF_TC_WITHOUT_HEAD(wmemcpy_before_end); +ATF_TC_BODY(wmemcpy_before_end, tc) { #define BUF &__stack.__buf struct { uint8_t padding_l; - unsigned char __buf[42]; + wchar_t __buf[42]; uint8_t padding_r; } __stack; const size_t __bufsz __unused = sizeof(__stack.__buf); const size_t __len = 42 - 1; const size_t __idx __unused = __len - 1; - char src[__len + 10]; + wchar_t src[__len + 10]; - memcpy(__stack.__buf, src, __len); + wmemcpy(__stack.__buf, src, __len); #undef BUF } -ATF_TC_WITHOUT_HEAD(memcpy_end); -ATF_TC_BODY(memcpy_end, tc) +ATF_TC_WITHOUT_HEAD(wmemcpy_end); +ATF_TC_BODY(wmemcpy_end, tc) { #define BUF &__stack.__buf struct { uint8_t padding_l; - unsigned char __buf[42]; + wchar_t __buf[42]; uint8_t padding_r; } __stack; const size_t __bufsz __unused = sizeof(__stack.__buf); const size_t __len = 42; const size_t __idx __unused = __len - 1; - char src[__len + 10]; + wchar_t src[__len + 10]; - memcpy(__stack.__buf, src, __len); + wmemcpy(__stack.__buf, src, __len); #undef BUF } -ATF_TC_WITHOUT_HEAD(memcpy_heap_before_end); -ATF_TC_BODY(memcpy_heap_before_end, tc) +ATF_TC_WITHOUT_HEAD(wmemcpy_heap_before_end); +ATF_TC_BODY(wmemcpy_heap_before_end, tc) { #define BUF __stack.__buf struct { uint8_t padding_l; - unsigned char * __buf; + wchar_t * __buf; uint8_t padding_r; } __stack; const size_t __bufsz __unused = sizeof(*__stack.__buf) * (42); const size_t __len = 42 - 1; const size_t __idx __unused = __len - 1; - char src[__len + 10]; + wchar_t src[__len + 10]; __stack.__buf = malloc(__bufsz); - memcpy(__stack.__buf, src, __len); + wmemcpy(__stack.__buf, src, __len); #undef BUF } -ATF_TC_WITHOUT_HEAD(memcpy_heap_end); -ATF_TC_BODY(memcpy_heap_end, tc) +ATF_TC_WITHOUT_HEAD(wmemcpy_heap_end); +ATF_TC_BODY(wmemcpy_heap_end, tc) { #define BUF __stack.__buf struct { uint8_t padding_l; - unsigned char * __buf; + wchar_t * __buf; uint8_t padding_r; } __stack; const size_t __bufsz __unused = sizeof(*__stack.__buf) * (42); const size_t __len = 42; const size_t __idx __unused = __len - 1; - char src[__len + 10]; + wchar_t src[__len + 10]; __stack.__buf = malloc(__bufsz); - memcpy(__stack.__buf, src, __len); + wmemcpy(__stack.__buf, src, __len); #undef BUF } -ATF_TC_WITHOUT_HEAD(memcpy_heap_after_end); -ATF_TC_BODY(memcpy_heap_after_end, tc) +ATF_TC_WITHOUT_HEAD(wmemcpy_heap_after_end); +ATF_TC_BODY(wmemcpy_heap_after_end, tc) { #define BUF __stack.__buf struct { uint8_t padding_l; - unsigned char * __buf; + wchar_t * __buf; uint8_t padding_r; } __stack; const size_t __bufsz __unused = sizeof(*__stack.__buf) * (42); @@ -207,7 +208,7 @@ const size_t __idx __unused = __len - 1; pid_t __child; int __status; - char src[__len + 10]; + wchar_t src[__len + 10]; __child = fork(); ATF_REQUIRE(__child >= 0); @@ -218,7 +219,7 @@ disable_coredumps(); __stack.__buf = malloc(__bufsz); - memcpy(__stack.__buf, src, __len); + wmemcpy(__stack.__buf, src, __len); _exit(EX_SOFTWARE); /* Should have aborted. */ monitor: @@ -245,93 +246,93 @@ } -ATF_TC_WITHOUT_HEAD(mempcpy_before_end); -ATF_TC_BODY(mempcpy_before_end, tc) +ATF_TC_WITHOUT_HEAD(wmempcpy_before_end); +ATF_TC_BODY(wmempcpy_before_end, tc) { #define BUF &__stack.__buf struct { uint8_t padding_l; - unsigned char __buf[42]; + wchar_t __buf[42]; uint8_t padding_r; } __stack; const size_t __bufsz __unused = sizeof(__stack.__buf); const size_t __len = 42 - 1; const size_t __idx __unused = __len - 1; - char src[__len + 10]; + wchar_t src[__len + 10]; - mempcpy(__stack.__buf, src, __len); + wmempcpy(__stack.__buf, src, __len); #undef BUF } -ATF_TC_WITHOUT_HEAD(mempcpy_end); -ATF_TC_BODY(mempcpy_end, tc) +ATF_TC_WITHOUT_HEAD(wmempcpy_end); +ATF_TC_BODY(wmempcpy_end, tc) { #define BUF &__stack.__buf struct { uint8_t padding_l; - unsigned char __buf[42]; + wchar_t __buf[42]; uint8_t padding_r; } __stack; const size_t __bufsz __unused = sizeof(__stack.__buf); const size_t __len = 42; const size_t __idx __unused = __len - 1; - char src[__len + 10]; + wchar_t src[__len + 10]; - mempcpy(__stack.__buf, src, __len); + wmempcpy(__stack.__buf, src, __len); #undef BUF } -ATF_TC_WITHOUT_HEAD(mempcpy_heap_before_end); -ATF_TC_BODY(mempcpy_heap_before_end, tc) +ATF_TC_WITHOUT_HEAD(wmempcpy_heap_before_end); +ATF_TC_BODY(wmempcpy_heap_before_end, tc) { #define BUF __stack.__buf struct { uint8_t padding_l; - unsigned char * __buf; + wchar_t * __buf; uint8_t padding_r; } __stack; const size_t __bufsz __unused = sizeof(*__stack.__buf) * (42); const size_t __len = 42 - 1; const size_t __idx __unused = __len - 1; - char src[__len + 10]; + wchar_t src[__len + 10]; __stack.__buf = malloc(__bufsz); - mempcpy(__stack.__buf, src, __len); + wmempcpy(__stack.__buf, src, __len); #undef BUF } -ATF_TC_WITHOUT_HEAD(mempcpy_heap_end); -ATF_TC_BODY(mempcpy_heap_end, tc) +ATF_TC_WITHOUT_HEAD(wmempcpy_heap_end); +ATF_TC_BODY(wmempcpy_heap_end, tc) { #define BUF __stack.__buf struct { uint8_t padding_l; - unsigned char * __buf; + wchar_t * __buf; uint8_t padding_r; } __stack; const size_t __bufsz __unused = sizeof(*__stack.__buf) * (42); const size_t __len = 42; const size_t __idx __unused = __len - 1; - char src[__len + 10]; + wchar_t src[__len + 10]; __stack.__buf = malloc(__bufsz); - mempcpy(__stack.__buf, src, __len); + wmempcpy(__stack.__buf, src, __len); #undef BUF } -ATF_TC_WITHOUT_HEAD(mempcpy_heap_after_end); -ATF_TC_BODY(mempcpy_heap_after_end, tc) +ATF_TC_WITHOUT_HEAD(wmempcpy_heap_after_end); +ATF_TC_BODY(wmempcpy_heap_after_end, tc) { #define BUF __stack.__buf struct { uint8_t padding_l; - unsigned char * __buf; + wchar_t * __buf; uint8_t padding_r; } __stack; const size_t __bufsz __unused = sizeof(*__stack.__buf) * (42); @@ -339,7 +340,7 @@ const size_t __idx __unused = __len - 1; pid_t __child; int __status; - char src[__len + 10]; + wchar_t src[__len + 10]; __child = fork(); ATF_REQUIRE(__child >= 0); @@ -350,7 +351,7 @@ disable_coredumps(); __stack.__buf = malloc(__bufsz); - mempcpy(__stack.__buf, src, __len); + wmempcpy(__stack.__buf, src, __len); _exit(EX_SOFTWARE); /* Should have aborted. */ monitor: @@ -377,93 +378,93 @@ } -ATF_TC_WITHOUT_HEAD(memmove_before_end); -ATF_TC_BODY(memmove_before_end, tc) +ATF_TC_WITHOUT_HEAD(wmemmove_before_end); +ATF_TC_BODY(wmemmove_before_end, tc) { #define BUF &__stack.__buf struct { uint8_t padding_l; - unsigned char __buf[42]; + wchar_t __buf[42]; uint8_t padding_r; } __stack; const size_t __bufsz __unused = sizeof(__stack.__buf); const size_t __len = 42 - 1; const size_t __idx __unused = __len - 1; - char src[__len + 10]; + wchar_t src[__len + 10]; - memmove(__stack.__buf, src, __len); + wmemmove(__stack.__buf, src, __len); #undef BUF } -ATF_TC_WITHOUT_HEAD(memmove_end); -ATF_TC_BODY(memmove_end, tc) +ATF_TC_WITHOUT_HEAD(wmemmove_end); +ATF_TC_BODY(wmemmove_end, tc) { #define BUF &__stack.__buf struct { uint8_t padding_l; - unsigned char __buf[42]; + wchar_t __buf[42]; uint8_t padding_r; } __stack; const size_t __bufsz __unused = sizeof(__stack.__buf); const size_t __len = 42; const size_t __idx __unused = __len - 1; - char src[__len + 10]; + wchar_t src[__len + 10]; - memmove(__stack.__buf, src, __len); + wmemmove(__stack.__buf, src, __len); #undef BUF } -ATF_TC_WITHOUT_HEAD(memmove_heap_before_end); -ATF_TC_BODY(memmove_heap_before_end, tc) +ATF_TC_WITHOUT_HEAD(wmemmove_heap_before_end); +ATF_TC_BODY(wmemmove_heap_before_end, tc) { #define BUF __stack.__buf struct { uint8_t padding_l; - unsigned char * __buf; + wchar_t * __buf; uint8_t padding_r; } __stack; const size_t __bufsz __unused = sizeof(*__stack.__buf) * (42); const size_t __len = 42 - 1; const size_t __idx __unused = __len - 1; - char src[__len + 10]; + wchar_t src[__len + 10]; __stack.__buf = malloc(__bufsz); - memmove(__stack.__buf, src, __len); + wmemmove(__stack.__buf, src, __len); #undef BUF } -ATF_TC_WITHOUT_HEAD(memmove_heap_end); -ATF_TC_BODY(memmove_heap_end, tc) +ATF_TC_WITHOUT_HEAD(wmemmove_heap_end); +ATF_TC_BODY(wmemmove_heap_end, tc) { #define BUF __stack.__buf struct { uint8_t padding_l; - unsigned char * __buf; + wchar_t * __buf; uint8_t padding_r; } __stack; const size_t __bufsz __unused = sizeof(*__stack.__buf) * (42); const size_t __len = 42; const size_t __idx __unused = __len - 1; - char src[__len + 10]; + wchar_t src[__len + 10]; __stack.__buf = malloc(__bufsz); - memmove(__stack.__buf, src, __len); + wmemmove(__stack.__buf, src, __len); #undef BUF } -ATF_TC_WITHOUT_HEAD(memmove_heap_after_end); -ATF_TC_BODY(memmove_heap_after_end, tc) +ATF_TC_WITHOUT_HEAD(wmemmove_heap_after_end); +ATF_TC_BODY(wmemmove_heap_after_end, tc) { #define BUF __stack.__buf struct { uint8_t padding_l; - unsigned char * __buf; + wchar_t * __buf; uint8_t padding_r; } __stack; const size_t __bufsz __unused = sizeof(*__stack.__buf) * (42); @@ -471,7 +472,7 @@ const size_t __idx __unused = __len - 1; pid_t __child; int __status; - char src[__len + 10]; + wchar_t src[__len + 10]; __child = fork(); ATF_REQUIRE(__child >= 0); @@ -482,7 +483,7 @@ disable_coredumps(); __stack.__buf = malloc(__bufsz); - memmove(__stack.__buf, src, __len); + wmemmove(__stack.__buf, src, __len); _exit(EX_SOFTWARE); /* Should have aborted. */ monitor: @@ -509,49 +510,49 @@ } -ATF_TC_WITHOUT_HEAD(memset_before_end); -ATF_TC_BODY(memset_before_end, tc) +ATF_TC_WITHOUT_HEAD(wmemset_before_end); +ATF_TC_BODY(wmemset_before_end, tc) { #define BUF &__stack.__buf struct { uint8_t padding_l; - unsigned char __buf[42]; + wchar_t __buf[42]; uint8_t padding_r; } __stack; const size_t __bufsz __unused = sizeof(__stack.__buf); const size_t __len = 42 - 1; const size_t __idx __unused = __len - 1; - memset(__stack.__buf, 0, __len); + wmemset(__stack.__buf, L'0', __len); #undef BUF } -ATF_TC_WITHOUT_HEAD(memset_end); -ATF_TC_BODY(memset_end, tc) +ATF_TC_WITHOUT_HEAD(wmemset_end); +ATF_TC_BODY(wmemset_end, tc) { #define BUF &__stack.__buf struct { uint8_t padding_l; - unsigned char __buf[42]; + wchar_t __buf[42]; uint8_t padding_r; } __stack; const size_t __bufsz __unused = sizeof(__stack.__buf); const size_t __len = 42; const size_t __idx __unused = __len - 1; - memset(__stack.__buf, 0, __len); + wmemset(__stack.__buf, L'0', __len); #undef BUF } -ATF_TC_WITHOUT_HEAD(memset_heap_before_end); -ATF_TC_BODY(memset_heap_before_end, tc) +ATF_TC_WITHOUT_HEAD(wmemset_heap_before_end); +ATF_TC_BODY(wmemset_heap_before_end, tc) { #define BUF __stack.__buf struct { uint8_t padding_l; - unsigned char * __buf; + wchar_t * __buf; uint8_t padding_r; } __stack; const size_t __bufsz __unused = sizeof(*__stack.__buf) * (42); @@ -560,18 +561,18 @@ __stack.__buf = malloc(__bufsz); - memset(__stack.__buf, 0, __len); + wmemset(__stack.__buf, L'0', __len); #undef BUF } -ATF_TC_WITHOUT_HEAD(memset_heap_end); -ATF_TC_BODY(memset_heap_end, tc) +ATF_TC_WITHOUT_HEAD(wmemset_heap_end); +ATF_TC_BODY(wmemset_heap_end, tc) { #define BUF __stack.__buf struct { uint8_t padding_l; - unsigned char * __buf; + wchar_t * __buf; uint8_t padding_r; } __stack; const size_t __bufsz __unused = sizeof(*__stack.__buf) * (42); @@ -580,18 +581,18 @@ __stack.__buf = malloc(__bufsz); - memset(__stack.__buf, 0, __len); + wmemset(__stack.__buf, L'0', __len); #undef BUF } -ATF_TC_WITHOUT_HEAD(memset_heap_after_end); -ATF_TC_BODY(memset_heap_after_end, tc) +ATF_TC_WITHOUT_HEAD(wmemset_heap_after_end); +ATF_TC_BODY(wmemset_heap_after_end, tc) { #define BUF __stack.__buf struct { uint8_t padding_l; - unsigned char * __buf; + wchar_t * __buf; uint8_t padding_r; } __stack; const size_t __bufsz __unused = sizeof(*__stack.__buf) * (42); @@ -609,7 +610,7 @@ disable_coredumps(); __stack.__buf = malloc(__bufsz); - memset(__stack.__buf, 0, __len); + wmemset(__stack.__buf, L'0', __len); _exit(EX_SOFTWARE); /* Should have aborted. */ monitor: @@ -636,107 +637,107 @@ } -ATF_TC_WITHOUT_HEAD(stpcpy_before_end); -ATF_TC_BODY(stpcpy_before_end, tc) +ATF_TC_WITHOUT_HEAD(wcpcpy_before_end); +ATF_TC_BODY(wcpcpy_before_end, tc) { #define BUF &__stack.__buf struct { uint8_t padding_l; - unsigned char __buf[42]; + wchar_t __buf[42]; uint8_t padding_r; } __stack; const size_t __bufsz __unused = sizeof(__stack.__buf); const size_t __len = 42 - 1; const size_t __idx __unused = __len - 1; - char src[__len]; + wchar_t src[__len]; - memset(__stack.__buf, 0, __len); - memset(src, 'A', __len - 1); + wmemset(__stack.__buf, 0, __len); + wmemset(src, 'A', __len - 1); src[__len - 1] = '\0'; - stpcpy(__stack.__buf, src); + wcpcpy(__stack.__buf, src); #undef BUF } -ATF_TC_WITHOUT_HEAD(stpcpy_end); -ATF_TC_BODY(stpcpy_end, tc) +ATF_TC_WITHOUT_HEAD(wcpcpy_end); +ATF_TC_BODY(wcpcpy_end, tc) { #define BUF &__stack.__buf struct { uint8_t padding_l; - unsigned char __buf[42]; + wchar_t __buf[42]; uint8_t padding_r; } __stack; const size_t __bufsz __unused = sizeof(__stack.__buf); const size_t __len = 42; const size_t __idx __unused = __len - 1; - char src[__len]; + wchar_t src[__len]; - memset(__stack.__buf, 0, __len); - memset(src, 'A', __len - 1); + wmemset(__stack.__buf, 0, __len); + wmemset(src, 'A', __len - 1); src[__len - 1] = '\0'; - stpcpy(__stack.__buf, src); + wcpcpy(__stack.__buf, src); #undef BUF } -ATF_TC_WITHOUT_HEAD(stpcpy_heap_before_end); -ATF_TC_BODY(stpcpy_heap_before_end, tc) +ATF_TC_WITHOUT_HEAD(wcpcpy_heap_before_end); +ATF_TC_BODY(wcpcpy_heap_before_end, tc) { #define BUF __stack.__buf struct { uint8_t padding_l; - unsigned char * __buf; + wchar_t * __buf; uint8_t padding_r; } __stack; const size_t __bufsz __unused = sizeof(*__stack.__buf) * (42); const size_t __len = 42 - 1; const size_t __idx __unused = __len - 1; - char src[__len]; + wchar_t src[__len]; __stack.__buf = malloc(__bufsz); - memset(__stack.__buf, 0, __len); - memset(src, 'A', __len - 1); + wmemset(__stack.__buf, 0, __len); + wmemset(src, 'A', __len - 1); src[__len - 1] = '\0'; - stpcpy(__stack.__buf, src); + wcpcpy(__stack.__buf, src); #undef BUF } -ATF_TC_WITHOUT_HEAD(stpcpy_heap_end); -ATF_TC_BODY(stpcpy_heap_end, tc) +ATF_TC_WITHOUT_HEAD(wcpcpy_heap_end); +ATF_TC_BODY(wcpcpy_heap_end, tc) { #define BUF __stack.__buf struct { uint8_t padding_l; - unsigned char * __buf; + wchar_t * __buf; uint8_t padding_r; } __stack; const size_t __bufsz __unused = sizeof(*__stack.__buf) * (42); const size_t __len = 42; const size_t __idx __unused = __len - 1; - char src[__len]; + wchar_t src[__len]; __stack.__buf = malloc(__bufsz); - memset(__stack.__buf, 0, __len); - memset(src, 'A', __len - 1); + wmemset(__stack.__buf, 0, __len); + wmemset(src, 'A', __len - 1); src[__len - 1] = '\0'; - stpcpy(__stack.__buf, src); + wcpcpy(__stack.__buf, src); #undef BUF } -ATF_TC_WITHOUT_HEAD(stpcpy_heap_after_end); -ATF_TC_BODY(stpcpy_heap_after_end, tc) +ATF_TC_WITHOUT_HEAD(wcpcpy_heap_after_end); +ATF_TC_BODY(wcpcpy_heap_after_end, tc) { #define BUF __stack.__buf struct { uint8_t padding_l; - unsigned char * __buf; + wchar_t * __buf; uint8_t padding_r; } __stack; const size_t __bufsz __unused = sizeof(*__stack.__buf) * (42); @@ -744,7 +745,7 @@ const size_t __idx __unused = __len - 1; pid_t __child; int __status; - char src[__len]; + wchar_t src[__len]; __child = fork(); ATF_REQUIRE(__child >= 0); @@ -754,11 +755,11 @@ /* Child */ disable_coredumps(); __stack.__buf = malloc(__bufsz); - memset(__stack.__buf, 0, __len); - memset(src, 'A', __len - 1); + wmemset(__stack.__buf, 0, __len); + wmemset(src, 'A', __len - 1); src[__len - 1] = '\0'; - stpcpy(__stack.__buf, src); + wcpcpy(__stack.__buf, src); _exit(EX_SOFTWARE); /* Should have aborted. */ monitor: @@ -785,107 +786,107 @@ } -ATF_TC_WITHOUT_HEAD(stpncpy_before_end); -ATF_TC_BODY(stpncpy_before_end, tc) +ATF_TC_WITHOUT_HEAD(wcpncpy_before_end); +ATF_TC_BODY(wcpncpy_before_end, tc) { #define BUF &__stack.__buf struct { uint8_t padding_l; - unsigned char __buf[42]; + wchar_t __buf[42]; uint8_t padding_r; } __stack; const size_t __bufsz __unused = sizeof(__stack.__buf); const size_t __len = 42 - 1; const size_t __idx __unused = __len - 1; - char src[__len]; + wchar_t src[__len]; - memset(__stack.__buf, 0, __len); - memset(src, 'A', __len - 1); + wmemset(__stack.__buf, 0, __len); + wmemset(src, 'A', __len - 1); src[__len - 1] = '\0'; - stpncpy(__stack.__buf, src, __len); + wcpncpy(__stack.__buf, src, __len); #undef BUF } -ATF_TC_WITHOUT_HEAD(stpncpy_end); -ATF_TC_BODY(stpncpy_end, tc) +ATF_TC_WITHOUT_HEAD(wcpncpy_end); +ATF_TC_BODY(wcpncpy_end, tc) { #define BUF &__stack.__buf struct { uint8_t padding_l; - unsigned char __buf[42]; + wchar_t __buf[42]; uint8_t padding_r; } __stack; const size_t __bufsz __unused = sizeof(__stack.__buf); const size_t __len = 42; const size_t __idx __unused = __len - 1; - char src[__len]; + wchar_t src[__len]; - memset(__stack.__buf, 0, __len); - memset(src, 'A', __len - 1); + wmemset(__stack.__buf, 0, __len); + wmemset(src, 'A', __len - 1); src[__len - 1] = '\0'; - stpncpy(__stack.__buf, src, __len); + wcpncpy(__stack.__buf, src, __len); #undef BUF } -ATF_TC_WITHOUT_HEAD(stpncpy_heap_before_end); -ATF_TC_BODY(stpncpy_heap_before_end, tc) +ATF_TC_WITHOUT_HEAD(wcpncpy_heap_before_end); +ATF_TC_BODY(wcpncpy_heap_before_end, tc) { #define BUF __stack.__buf struct { uint8_t padding_l; - unsigned char * __buf; + wchar_t * __buf; uint8_t padding_r; } __stack; const size_t __bufsz __unused = sizeof(*__stack.__buf) * (42); const size_t __len = 42 - 1; const size_t __idx __unused = __len - 1; - char src[__len]; + wchar_t src[__len]; __stack.__buf = malloc(__bufsz); - memset(__stack.__buf, 0, __len); - memset(src, 'A', __len - 1); + wmemset(__stack.__buf, 0, __len); + wmemset(src, 'A', __len - 1); src[__len - 1] = '\0'; - stpncpy(__stack.__buf, src, __len); + wcpncpy(__stack.__buf, src, __len); #undef BUF } -ATF_TC_WITHOUT_HEAD(stpncpy_heap_end); -ATF_TC_BODY(stpncpy_heap_end, tc) +ATF_TC_WITHOUT_HEAD(wcpncpy_heap_end); +ATF_TC_BODY(wcpncpy_heap_end, tc) { #define BUF __stack.__buf struct { uint8_t padding_l; - unsigned char * __buf; + wchar_t * __buf; uint8_t padding_r; } __stack; const size_t __bufsz __unused = sizeof(*__stack.__buf) * (42); const size_t __len = 42; const size_t __idx __unused = __len - 1; - char src[__len]; + wchar_t src[__len]; __stack.__buf = malloc(__bufsz); - memset(__stack.__buf, 0, __len); - memset(src, 'A', __len - 1); + wmemset(__stack.__buf, 0, __len); + wmemset(src, 'A', __len - 1); src[__len - 1] = '\0'; - stpncpy(__stack.__buf, src, __len); + wcpncpy(__stack.__buf, src, __len); #undef BUF } -ATF_TC_WITHOUT_HEAD(stpncpy_heap_after_end); -ATF_TC_BODY(stpncpy_heap_after_end, tc) +ATF_TC_WITHOUT_HEAD(wcpncpy_heap_after_end); +ATF_TC_BODY(wcpncpy_heap_after_end, tc) { #define BUF __stack.__buf struct { uint8_t padding_l; - unsigned char * __buf; + wchar_t * __buf; uint8_t padding_r; } __stack; const size_t __bufsz __unused = sizeof(*__stack.__buf) * (42); @@ -893,7 +894,7 @@ const size_t __idx __unused = __len - 1; pid_t __child; int __status; - char src[__len]; + wchar_t src[__len]; __child = fork(); ATF_REQUIRE(__child >= 0); @@ -903,11 +904,11 @@ /* Child */ disable_coredumps(); __stack.__buf = malloc(__bufsz); - memset(__stack.__buf, 0, __len); - memset(src, 'A', __len - 1); + wmemset(__stack.__buf, 0, __len); + wmemset(src, 'A', __len - 1); src[__len - 1] = '\0'; - stpncpy(__stack.__buf, src, __len); + wcpncpy(__stack.__buf, src, __len); _exit(EX_SOFTWARE); /* Should have aborted. */ monitor: @@ -934,107 +935,107 @@ } -ATF_TC_WITHOUT_HEAD(strcat_before_end); -ATF_TC_BODY(strcat_before_end, tc) +ATF_TC_WITHOUT_HEAD(wcscat_before_end); +ATF_TC_BODY(wcscat_before_end, tc) { #define BUF &__stack.__buf struct { uint8_t padding_l; - unsigned char __buf[42]; + wchar_t __buf[42]; uint8_t padding_r; } __stack; const size_t __bufsz __unused = sizeof(__stack.__buf); const size_t __len = 42 - 1; const size_t __idx __unused = __len - 1; - char src[__len]; + wchar_t src[__len]; - memset(__stack.__buf, 0, __len); - memset(src, 'A', __len - 1); + wmemset(__stack.__buf, 0, __len); + wmemset(src, 'A', __len - 1); src[__len - 1] = '\0'; - strcat(__stack.__buf, src); + wcscat(__stack.__buf, src); #undef BUF } -ATF_TC_WITHOUT_HEAD(strcat_end); -ATF_TC_BODY(strcat_end, tc) +ATF_TC_WITHOUT_HEAD(wcscat_end); +ATF_TC_BODY(wcscat_end, tc) { #define BUF &__stack.__buf struct { uint8_t padding_l; - unsigned char __buf[42]; + wchar_t __buf[42]; uint8_t padding_r; } __stack; const size_t __bufsz __unused = sizeof(__stack.__buf); const size_t __len = 42; const size_t __idx __unused = __len - 1; - char src[__len]; + wchar_t src[__len]; - memset(__stack.__buf, 0, __len); - memset(src, 'A', __len - 1); + wmemset(__stack.__buf, 0, __len); + wmemset(src, 'A', __len - 1); src[__len - 1] = '\0'; - strcat(__stack.__buf, src); + wcscat(__stack.__buf, src); #undef BUF } -ATF_TC_WITHOUT_HEAD(strcat_heap_before_end); -ATF_TC_BODY(strcat_heap_before_end, tc) +ATF_TC_WITHOUT_HEAD(wcscat_heap_before_end); +ATF_TC_BODY(wcscat_heap_before_end, tc) { #define BUF __stack.__buf struct { uint8_t padding_l; - unsigned char * __buf; + wchar_t * __buf; uint8_t padding_r; } __stack; const size_t __bufsz __unused = sizeof(*__stack.__buf) * (42); const size_t __len = 42 - 1; const size_t __idx __unused = __len - 1; - char src[__len]; + wchar_t src[__len]; __stack.__buf = malloc(__bufsz); - memset(__stack.__buf, 0, __len); - memset(src, 'A', __len - 1); + wmemset(__stack.__buf, 0, __len); + wmemset(src, 'A', __len - 1); src[__len - 1] = '\0'; - strcat(__stack.__buf, src); + wcscat(__stack.__buf, src); #undef BUF } -ATF_TC_WITHOUT_HEAD(strcat_heap_end); -ATF_TC_BODY(strcat_heap_end, tc) +ATF_TC_WITHOUT_HEAD(wcscat_heap_end); +ATF_TC_BODY(wcscat_heap_end, tc) { #define BUF __stack.__buf struct { uint8_t padding_l; - unsigned char * __buf; + wchar_t * __buf; uint8_t padding_r; } __stack; const size_t __bufsz __unused = sizeof(*__stack.__buf) * (42); const size_t __len = 42; const size_t __idx __unused = __len - 1; - char src[__len]; + wchar_t src[__len]; __stack.__buf = malloc(__bufsz); - memset(__stack.__buf, 0, __len); - memset(src, 'A', __len - 1); + wmemset(__stack.__buf, 0, __len); + wmemset(src, 'A', __len - 1); src[__len - 1] = '\0'; - strcat(__stack.__buf, src); + wcscat(__stack.__buf, src); #undef BUF } -ATF_TC_WITHOUT_HEAD(strcat_heap_after_end); -ATF_TC_BODY(strcat_heap_after_end, tc) +ATF_TC_WITHOUT_HEAD(wcscat_heap_after_end); +ATF_TC_BODY(wcscat_heap_after_end, tc) { #define BUF __stack.__buf struct { uint8_t padding_l; - unsigned char * __buf; + wchar_t * __buf; uint8_t padding_r; } __stack; const size_t __bufsz __unused = sizeof(*__stack.__buf) * (42); @@ -1042,7 +1043,7 @@ const size_t __idx __unused = __len - 1; pid_t __child; int __status; - char src[__len]; + wchar_t src[__len]; __child = fork(); ATF_REQUIRE(__child >= 0); @@ -1052,11 +1053,11 @@ /* Child */ disable_coredumps(); __stack.__buf = malloc(__bufsz); - memset(__stack.__buf, 0, __len); - memset(src, 'A', __len - 1); + wmemset(__stack.__buf, 0, __len); + wmemset(src, 'A', __len - 1); src[__len - 1] = '\0'; - strcat(__stack.__buf, src); + wcscat(__stack.__buf, src); _exit(EX_SOFTWARE); /* Should have aborted. */ monitor: @@ -1083,107 +1084,107 @@ } -ATF_TC_WITHOUT_HEAD(strlcat_before_end); -ATF_TC_BODY(strlcat_before_end, tc) +ATF_TC_WITHOUT_HEAD(wcslcat_before_end); +ATF_TC_BODY(wcslcat_before_end, tc) { #define BUF &__stack.__buf struct { uint8_t padding_l; - unsigned char __buf[42]; + wchar_t __buf[42]; uint8_t padding_r; } __stack; const size_t __bufsz __unused = sizeof(__stack.__buf); const size_t __len = 42 - 1; const size_t __idx __unused = __len - 1; - char src[__len]; + wchar_t src[__len]; - memset(__stack.__buf, 0, __len); - memset(src, 'A', __len - 1); + wmemset(__stack.__buf, 0, __len); + wmemset(src, 'A', __len - 1); src[__len - 1] = '\0'; - strlcat(__stack.__buf, src, __len); + wcslcat(__stack.__buf, src, __len); #undef BUF } -ATF_TC_WITHOUT_HEAD(strlcat_end); -ATF_TC_BODY(strlcat_end, tc) +ATF_TC_WITHOUT_HEAD(wcslcat_end); +ATF_TC_BODY(wcslcat_end, tc) { #define BUF &__stack.__buf struct { uint8_t padding_l; - unsigned char __buf[42]; + wchar_t __buf[42]; uint8_t padding_r; } __stack; const size_t __bufsz __unused = sizeof(__stack.__buf); const size_t __len = 42; const size_t __idx __unused = __len - 1; - char src[__len]; + wchar_t src[__len]; - memset(__stack.__buf, 0, __len); - memset(src, 'A', __len - 1); + wmemset(__stack.__buf, 0, __len); + wmemset(src, 'A', __len - 1); src[__len - 1] = '\0'; - strlcat(__stack.__buf, src, __len); + wcslcat(__stack.__buf, src, __len); #undef BUF } -ATF_TC_WITHOUT_HEAD(strlcat_heap_before_end); -ATF_TC_BODY(strlcat_heap_before_end, tc) +ATF_TC_WITHOUT_HEAD(wcslcat_heap_before_end); +ATF_TC_BODY(wcslcat_heap_before_end, tc) { #define BUF __stack.__buf struct { uint8_t padding_l; - unsigned char * __buf; + wchar_t * __buf; uint8_t padding_r; } __stack; const size_t __bufsz __unused = sizeof(*__stack.__buf) * (42); const size_t __len = 42 - 1; const size_t __idx __unused = __len - 1; - char src[__len]; + wchar_t src[__len]; __stack.__buf = malloc(__bufsz); - memset(__stack.__buf, 0, __len); - memset(src, 'A', __len - 1); + wmemset(__stack.__buf, 0, __len); + wmemset(src, 'A', __len - 1); src[__len - 1] = '\0'; - strlcat(__stack.__buf, src, __len); + wcslcat(__stack.__buf, src, __len); #undef BUF } -ATF_TC_WITHOUT_HEAD(strlcat_heap_end); -ATF_TC_BODY(strlcat_heap_end, tc) +ATF_TC_WITHOUT_HEAD(wcslcat_heap_end); +ATF_TC_BODY(wcslcat_heap_end, tc) { #define BUF __stack.__buf struct { uint8_t padding_l; - unsigned char * __buf; + wchar_t * __buf; uint8_t padding_r; } __stack; const size_t __bufsz __unused = sizeof(*__stack.__buf) * (42); const size_t __len = 42; const size_t __idx __unused = __len - 1; - char src[__len]; + wchar_t src[__len]; __stack.__buf = malloc(__bufsz); - memset(__stack.__buf, 0, __len); - memset(src, 'A', __len - 1); + wmemset(__stack.__buf, 0, __len); + wmemset(src, 'A', __len - 1); src[__len - 1] = '\0'; - strlcat(__stack.__buf, src, __len); + wcslcat(__stack.__buf, src, __len); #undef BUF } -ATF_TC_WITHOUT_HEAD(strlcat_heap_after_end); -ATF_TC_BODY(strlcat_heap_after_end, tc) +ATF_TC_WITHOUT_HEAD(wcslcat_heap_after_end); +ATF_TC_BODY(wcslcat_heap_after_end, tc) { #define BUF __stack.__buf struct { uint8_t padding_l; - unsigned char * __buf; + wchar_t * __buf; uint8_t padding_r; } __stack; const size_t __bufsz __unused = sizeof(*__stack.__buf) * (42); @@ -1191,7 +1192,7 @@ const size_t __idx __unused = __len - 1; pid_t __child; int __status; - char src[__len]; + wchar_t src[__len]; __child = fork(); ATF_REQUIRE(__child >= 0); @@ -1201,11 +1202,11 @@ /* Child */ disable_coredumps(); __stack.__buf = malloc(__bufsz); - memset(__stack.__buf, 0, __len); - memset(src, 'A', __len - 1); + wmemset(__stack.__buf, 0, __len); + wmemset(src, 'A', __len - 1); src[__len - 1] = '\0'; - strlcat(__stack.__buf, src, __len); + wcslcat(__stack.__buf, src, __len); _exit(EX_SOFTWARE); /* Should have aborted. */ monitor: @@ -1232,107 +1233,107 @@ } -ATF_TC_WITHOUT_HEAD(strncat_before_end); -ATF_TC_BODY(strncat_before_end, tc) +ATF_TC_WITHOUT_HEAD(wcsncat_before_end); +ATF_TC_BODY(wcsncat_before_end, tc) { #define BUF &__stack.__buf struct { uint8_t padding_l; - unsigned char __buf[42]; + wchar_t __buf[42]; uint8_t padding_r; } __stack; const size_t __bufsz __unused = sizeof(__stack.__buf); const size_t __len = 42 - 1; const size_t __idx __unused = __len - 1; - char src[__len]; + wchar_t src[__len]; - memset(__stack.__buf, 0, __len); - memset(src, 'A', __len - 1); + wmemset(__stack.__buf, 0, __len); + wmemset(src, 'A', __len - 1); src[__len - 1] = '\0'; - strncat(__stack.__buf, src, __len); + wcsncat(__stack.__buf, src, __len); #undef BUF } -ATF_TC_WITHOUT_HEAD(strncat_end); -ATF_TC_BODY(strncat_end, tc) +ATF_TC_WITHOUT_HEAD(wcsncat_end); +ATF_TC_BODY(wcsncat_end, tc) { #define BUF &__stack.__buf struct { uint8_t padding_l; - unsigned char __buf[42]; + wchar_t __buf[42]; uint8_t padding_r; } __stack; const size_t __bufsz __unused = sizeof(__stack.__buf); const size_t __len = 42; const size_t __idx __unused = __len - 1; - char src[__len]; + wchar_t src[__len]; - memset(__stack.__buf, 0, __len); - memset(src, 'A', __len - 1); + wmemset(__stack.__buf, 0, __len); + wmemset(src, 'A', __len - 1); src[__len - 1] = '\0'; - strncat(__stack.__buf, src, __len); + wcsncat(__stack.__buf, src, __len); #undef BUF } -ATF_TC_WITHOUT_HEAD(strncat_heap_before_end); -ATF_TC_BODY(strncat_heap_before_end, tc) +ATF_TC_WITHOUT_HEAD(wcsncat_heap_before_end); +ATF_TC_BODY(wcsncat_heap_before_end, tc) { #define BUF __stack.__buf struct { uint8_t padding_l; - unsigned char * __buf; + wchar_t * __buf; uint8_t padding_r; } __stack; const size_t __bufsz __unused = sizeof(*__stack.__buf) * (42); const size_t __len = 42 - 1; const size_t __idx __unused = __len - 1; - char src[__len]; + wchar_t src[__len]; __stack.__buf = malloc(__bufsz); - memset(__stack.__buf, 0, __len); - memset(src, 'A', __len - 1); + wmemset(__stack.__buf, 0, __len); + wmemset(src, 'A', __len - 1); src[__len - 1] = '\0'; - strncat(__stack.__buf, src, __len); + wcsncat(__stack.__buf, src, __len); #undef BUF } -ATF_TC_WITHOUT_HEAD(strncat_heap_end); -ATF_TC_BODY(strncat_heap_end, tc) +ATF_TC_WITHOUT_HEAD(wcsncat_heap_end); +ATF_TC_BODY(wcsncat_heap_end, tc) { #define BUF __stack.__buf struct { uint8_t padding_l; - unsigned char * __buf; + wchar_t * __buf; uint8_t padding_r; } __stack; const size_t __bufsz __unused = sizeof(*__stack.__buf) * (42); const size_t __len = 42; const size_t __idx __unused = __len - 1; - char src[__len]; + wchar_t src[__len]; __stack.__buf = malloc(__bufsz); - memset(__stack.__buf, 0, __len); - memset(src, 'A', __len - 1); + wmemset(__stack.__buf, 0, __len); + wmemset(src, 'A', __len - 1); src[__len - 1] = '\0'; - strncat(__stack.__buf, src, __len); + wcsncat(__stack.__buf, src, __len); #undef BUF } -ATF_TC_WITHOUT_HEAD(strncat_heap_after_end); -ATF_TC_BODY(strncat_heap_after_end, tc) +ATF_TC_WITHOUT_HEAD(wcsncat_heap_after_end); +ATF_TC_BODY(wcsncat_heap_after_end, tc) { #define BUF __stack.__buf struct { uint8_t padding_l; - unsigned char * __buf; + wchar_t * __buf; uint8_t padding_r; } __stack; const size_t __bufsz __unused = sizeof(*__stack.__buf) * (42); @@ -1340,7 +1341,7 @@ const size_t __idx __unused = __len - 1; pid_t __child; int __status; - char src[__len]; + wchar_t src[__len]; __child = fork(); ATF_REQUIRE(__child >= 0); @@ -1350,11 +1351,11 @@ /* Child */ disable_coredumps(); __stack.__buf = malloc(__bufsz); - memset(__stack.__buf, 0, __len); - memset(src, 'A', __len - 1); + wmemset(__stack.__buf, 0, __len); + wmemset(src, 'A', __len - 1); src[__len - 1] = '\0'; - strncat(__stack.__buf, src, __len); + wcsncat(__stack.__buf, src, __len); _exit(EX_SOFTWARE); /* Should have aborted. */ monitor: @@ -1381,107 +1382,107 @@ } -ATF_TC_WITHOUT_HEAD(strcpy_before_end); -ATF_TC_BODY(strcpy_before_end, tc) +ATF_TC_WITHOUT_HEAD(wcscpy_before_end); +ATF_TC_BODY(wcscpy_before_end, tc) { #define BUF &__stack.__buf struct { uint8_t padding_l; - unsigned char __buf[42]; + wchar_t __buf[42]; uint8_t padding_r; } __stack; const size_t __bufsz __unused = sizeof(__stack.__buf); const size_t __len = 42 - 1; const size_t __idx __unused = __len - 1; - char src[__len]; + wchar_t src[__len]; - memset(__stack.__buf, 0, __len); - memset(src, 'A', __len - 1); + wmemset(__stack.__buf, 0, __len); + wmemset(src, 'A', __len - 1); src[__len - 1] = '\0'; - strcpy(__stack.__buf, src); + wcscpy(__stack.__buf, src); #undef BUF } -ATF_TC_WITHOUT_HEAD(strcpy_end); -ATF_TC_BODY(strcpy_end, tc) +ATF_TC_WITHOUT_HEAD(wcscpy_end); +ATF_TC_BODY(wcscpy_end, tc) { #define BUF &__stack.__buf struct { uint8_t padding_l; - unsigned char __buf[42]; + wchar_t __buf[42]; uint8_t padding_r; } __stack; const size_t __bufsz __unused = sizeof(__stack.__buf); const size_t __len = 42; const size_t __idx __unused = __len - 1; - char src[__len]; + wchar_t src[__len]; - memset(__stack.__buf, 0, __len); - memset(src, 'A', __len - 1); + wmemset(__stack.__buf, 0, __len); + wmemset(src, 'A', __len - 1); src[__len - 1] = '\0'; - strcpy(__stack.__buf, src); + wcscpy(__stack.__buf, src); #undef BUF } -ATF_TC_WITHOUT_HEAD(strcpy_heap_before_end); -ATF_TC_BODY(strcpy_heap_before_end, tc) +ATF_TC_WITHOUT_HEAD(wcscpy_heap_before_end); +ATF_TC_BODY(wcscpy_heap_before_end, tc) { #define BUF __stack.__buf struct { uint8_t padding_l; - unsigned char * __buf; + wchar_t * __buf; uint8_t padding_r; } __stack; const size_t __bufsz __unused = sizeof(*__stack.__buf) * (42); const size_t __len = 42 - 1; const size_t __idx __unused = __len - 1; - char src[__len]; + wchar_t src[__len]; __stack.__buf = malloc(__bufsz); - memset(__stack.__buf, 0, __len); - memset(src, 'A', __len - 1); + wmemset(__stack.__buf, 0, __len); + wmemset(src, 'A', __len - 1); src[__len - 1] = '\0'; - strcpy(__stack.__buf, src); + wcscpy(__stack.__buf, src); #undef BUF } -ATF_TC_WITHOUT_HEAD(strcpy_heap_end); -ATF_TC_BODY(strcpy_heap_end, tc) +ATF_TC_WITHOUT_HEAD(wcscpy_heap_end); +ATF_TC_BODY(wcscpy_heap_end, tc) { #define BUF __stack.__buf struct { uint8_t padding_l; - unsigned char * __buf; + wchar_t * __buf; uint8_t padding_r; } __stack; const size_t __bufsz __unused = sizeof(*__stack.__buf) * (42); const size_t __len = 42; const size_t __idx __unused = __len - 1; - char src[__len]; + wchar_t src[__len]; __stack.__buf = malloc(__bufsz); - memset(__stack.__buf, 0, __len); - memset(src, 'A', __len - 1); + wmemset(__stack.__buf, 0, __len); + wmemset(src, 'A', __len - 1); src[__len - 1] = '\0'; - strcpy(__stack.__buf, src); + wcscpy(__stack.__buf, src); #undef BUF } -ATF_TC_WITHOUT_HEAD(strcpy_heap_after_end); -ATF_TC_BODY(strcpy_heap_after_end, tc) +ATF_TC_WITHOUT_HEAD(wcscpy_heap_after_end); +ATF_TC_BODY(wcscpy_heap_after_end, tc) { #define BUF __stack.__buf struct { uint8_t padding_l; - unsigned char * __buf; + wchar_t * __buf; uint8_t padding_r; } __stack; const size_t __bufsz __unused = sizeof(*__stack.__buf) * (42); @@ -1489,7 +1490,7 @@ const size_t __idx __unused = __len - 1; pid_t __child; int __status; - char src[__len]; + wchar_t src[__len]; __child = fork(); ATF_REQUIRE(__child >= 0); @@ -1499,11 +1500,11 @@ /* Child */ disable_coredumps(); __stack.__buf = malloc(__bufsz); - memset(__stack.__buf, 0, __len); - memset(src, 'A', __len - 1); + wmemset(__stack.__buf, 0, __len); + wmemset(src, 'A', __len - 1); src[__len - 1] = '\0'; - strcpy(__stack.__buf, src); + wcscpy(__stack.__buf, src); _exit(EX_SOFTWARE); /* Should have aborted. */ monitor: @@ -1530,107 +1531,107 @@ } -ATF_TC_WITHOUT_HEAD(strlcpy_before_end); -ATF_TC_BODY(strlcpy_before_end, tc) +ATF_TC_WITHOUT_HEAD(wcslcpy_before_end); +ATF_TC_BODY(wcslcpy_before_end, tc) { #define BUF &__stack.__buf struct { uint8_t padding_l; - unsigned char __buf[42]; + wchar_t __buf[42]; uint8_t padding_r; } __stack; const size_t __bufsz __unused = sizeof(__stack.__buf); const size_t __len = 42 - 1; const size_t __idx __unused = __len - 1; - char src[__len]; + wchar_t src[__len]; - memset(__stack.__buf, 0, __len); - memset(src, 'A', __len - 1); + wmemset(__stack.__buf, 0, __len); + wmemset(src, 'A', __len - 1); src[__len - 1] = '\0'; - strlcpy(__stack.__buf, src, __len); + wcslcpy(__stack.__buf, src, __len); #undef BUF } -ATF_TC_WITHOUT_HEAD(strlcpy_end); -ATF_TC_BODY(strlcpy_end, tc) +ATF_TC_WITHOUT_HEAD(wcslcpy_end); +ATF_TC_BODY(wcslcpy_end, tc) { #define BUF &__stack.__buf struct { uint8_t padding_l; - unsigned char __buf[42]; + wchar_t __buf[42]; uint8_t padding_r; } __stack; const size_t __bufsz __unused = sizeof(__stack.__buf); const size_t __len = 42; const size_t __idx __unused = __len - 1; - char src[__len]; + wchar_t src[__len]; - memset(__stack.__buf, 0, __len); - memset(src, 'A', __len - 1); + wmemset(__stack.__buf, 0, __len); + wmemset(src, 'A', __len - 1); src[__len - 1] = '\0'; - strlcpy(__stack.__buf, src, __len); + wcslcpy(__stack.__buf, src, __len); #undef BUF } -ATF_TC_WITHOUT_HEAD(strlcpy_heap_before_end); -ATF_TC_BODY(strlcpy_heap_before_end, tc) +ATF_TC_WITHOUT_HEAD(wcslcpy_heap_before_end); +ATF_TC_BODY(wcslcpy_heap_before_end, tc) { #define BUF __stack.__buf struct { uint8_t padding_l; - unsigned char * __buf; + wchar_t * __buf; uint8_t padding_r; } __stack; const size_t __bufsz __unused = sizeof(*__stack.__buf) * (42); const size_t __len = 42 - 1; const size_t __idx __unused = __len - 1; - char src[__len]; + wchar_t src[__len]; __stack.__buf = malloc(__bufsz); - memset(__stack.__buf, 0, __len); - memset(src, 'A', __len - 1); + wmemset(__stack.__buf, 0, __len); + wmemset(src, 'A', __len - 1); src[__len - 1] = '\0'; - strlcpy(__stack.__buf, src, __len); + wcslcpy(__stack.__buf, src, __len); #undef BUF } -ATF_TC_WITHOUT_HEAD(strlcpy_heap_end); -ATF_TC_BODY(strlcpy_heap_end, tc) +ATF_TC_WITHOUT_HEAD(wcslcpy_heap_end); +ATF_TC_BODY(wcslcpy_heap_end, tc) { #define BUF __stack.__buf struct { uint8_t padding_l; - unsigned char * __buf; + wchar_t * __buf; uint8_t padding_r; } __stack; const size_t __bufsz __unused = sizeof(*__stack.__buf) * (42); const size_t __len = 42; const size_t __idx __unused = __len - 1; - char src[__len]; + wchar_t src[__len]; __stack.__buf = malloc(__bufsz); - memset(__stack.__buf, 0, __len); - memset(src, 'A', __len - 1); + wmemset(__stack.__buf, 0, __len); + wmemset(src, 'A', __len - 1); src[__len - 1] = '\0'; - strlcpy(__stack.__buf, src, __len); + wcslcpy(__stack.__buf, src, __len); #undef BUF } -ATF_TC_WITHOUT_HEAD(strlcpy_heap_after_end); -ATF_TC_BODY(strlcpy_heap_after_end, tc) +ATF_TC_WITHOUT_HEAD(wcslcpy_heap_after_end); +ATF_TC_BODY(wcslcpy_heap_after_end, tc) { #define BUF __stack.__buf struct { uint8_t padding_l; - unsigned char * __buf; + wchar_t * __buf; uint8_t padding_r; } __stack; const size_t __bufsz __unused = sizeof(*__stack.__buf) * (42); @@ -1638,7 +1639,7 @@ const size_t __idx __unused = __len - 1; pid_t __child; int __status; - char src[__len]; + wchar_t src[__len]; __child = fork(); ATF_REQUIRE(__child >= 0); @@ -1648,11 +1649,11 @@ /* Child */ disable_coredumps(); __stack.__buf = malloc(__bufsz); - memset(__stack.__buf, 0, __len); - memset(src, 'A', __len - 1); + wmemset(__stack.__buf, 0, __len); + wmemset(src, 'A', __len - 1); src[__len - 1] = '\0'; - strlcpy(__stack.__buf, src, __len); + wcslcpy(__stack.__buf, src, __len); _exit(EX_SOFTWARE); /* Should have aborted. */ monitor: @@ -1679,107 +1680,107 @@ } -ATF_TC_WITHOUT_HEAD(strncpy_before_end); -ATF_TC_BODY(strncpy_before_end, tc) +ATF_TC_WITHOUT_HEAD(wcsncpy_before_end); +ATF_TC_BODY(wcsncpy_before_end, tc) { #define BUF &__stack.__buf struct { uint8_t padding_l; - unsigned char __buf[42]; + wchar_t __buf[42]; uint8_t padding_r; } __stack; const size_t __bufsz __unused = sizeof(__stack.__buf); const size_t __len = 42 - 1; const size_t __idx __unused = __len - 1; - char src[__len]; + wchar_t src[__len]; - memset(__stack.__buf, 0, __len); - memset(src, 'A', __len - 1); + wmemset(__stack.__buf, 0, __len); + wmemset(src, 'A', __len - 1); src[__len - 1] = '\0'; - strncpy(__stack.__buf, src, __len); + wcsncpy(__stack.__buf, src, __len); #undef BUF } -ATF_TC_WITHOUT_HEAD(strncpy_end); -ATF_TC_BODY(strncpy_end, tc) +ATF_TC_WITHOUT_HEAD(wcsncpy_end); +ATF_TC_BODY(wcsncpy_end, tc) { #define BUF &__stack.__buf struct { uint8_t padding_l; - unsigned char __buf[42]; + wchar_t __buf[42]; uint8_t padding_r; } __stack; const size_t __bufsz __unused = sizeof(__stack.__buf); const size_t __len = 42; const size_t __idx __unused = __len - 1; - char src[__len]; + wchar_t src[__len]; - memset(__stack.__buf, 0, __len); - memset(src, 'A', __len - 1); + wmemset(__stack.__buf, 0, __len); + wmemset(src, 'A', __len - 1); src[__len - 1] = '\0'; - strncpy(__stack.__buf, src, __len); + wcsncpy(__stack.__buf, src, __len); #undef BUF } -ATF_TC_WITHOUT_HEAD(strncpy_heap_before_end); -ATF_TC_BODY(strncpy_heap_before_end, tc) +ATF_TC_WITHOUT_HEAD(wcsncpy_heap_before_end); +ATF_TC_BODY(wcsncpy_heap_before_end, tc) { #define BUF __stack.__buf struct { uint8_t padding_l; - unsigned char * __buf; + wchar_t * __buf; uint8_t padding_r; } __stack; const size_t __bufsz __unused = sizeof(*__stack.__buf) * (42); const size_t __len = 42 - 1; const size_t __idx __unused = __len - 1; - char src[__len]; + wchar_t src[__len]; __stack.__buf = malloc(__bufsz); - memset(__stack.__buf, 0, __len); - memset(src, 'A', __len - 1); + wmemset(__stack.__buf, 0, __len); + wmemset(src, 'A', __len - 1); src[__len - 1] = '\0'; - strncpy(__stack.__buf, src, __len); + wcsncpy(__stack.__buf, src, __len); #undef BUF } -ATF_TC_WITHOUT_HEAD(strncpy_heap_end); -ATF_TC_BODY(strncpy_heap_end, tc) +ATF_TC_WITHOUT_HEAD(wcsncpy_heap_end); +ATF_TC_BODY(wcsncpy_heap_end, tc) { #define BUF __stack.__buf struct { uint8_t padding_l; - unsigned char * __buf; + wchar_t * __buf; uint8_t padding_r; } __stack; const size_t __bufsz __unused = sizeof(*__stack.__buf) * (42); const size_t __len = 42; const size_t __idx __unused = __len - 1; - char src[__len]; + wchar_t src[__len]; __stack.__buf = malloc(__bufsz); - memset(__stack.__buf, 0, __len); - memset(src, 'A', __len - 1); + wmemset(__stack.__buf, 0, __len); + wmemset(src, 'A', __len - 1); src[__len - 1] = '\0'; - strncpy(__stack.__buf, src, __len); + wcsncpy(__stack.__buf, src, __len); #undef BUF } -ATF_TC_WITHOUT_HEAD(strncpy_heap_after_end); -ATF_TC_BODY(strncpy_heap_after_end, tc) +ATF_TC_WITHOUT_HEAD(wcsncpy_heap_after_end); +ATF_TC_BODY(wcsncpy_heap_after_end, tc) { #define BUF __stack.__buf struct { uint8_t padding_l; - unsigned char * __buf; + wchar_t * __buf; uint8_t padding_r; } __stack; const size_t __bufsz __unused = sizeof(*__stack.__buf) * (42); @@ -1787,7 +1788,7 @@ const size_t __idx __unused = __len - 1; pid_t __child; int __status; - char src[__len]; + wchar_t src[__len]; __child = fork(); ATF_REQUIRE(__child >= 0); @@ -1797,11 +1798,11 @@ /* Child */ disable_coredumps(); __stack.__buf = malloc(__bufsz); - memset(__stack.__buf, 0, __len); - memset(src, 'A', __len - 1); + wmemset(__stack.__buf, 0, __len); + wmemset(src, 'A', __len - 1); src[__len - 1] = '\0'; - strncpy(__stack.__buf, src, __len); + wcsncpy(__stack.__buf, src, __len); _exit(EX_SOFTWARE); /* Should have aborted. */ monitor: @@ -1830,65 +1831,65 @@ ATF_TP_ADD_TCS(tp) { - ATF_TP_ADD_TC(tp, memcpy_before_end); - ATF_TP_ADD_TC(tp, memcpy_end); - ATF_TP_ADD_TC(tp, memcpy_heap_before_end); - ATF_TP_ADD_TC(tp, memcpy_heap_end); - ATF_TP_ADD_TC(tp, memcpy_heap_after_end); - ATF_TP_ADD_TC(tp, mempcpy_before_end); - ATF_TP_ADD_TC(tp, mempcpy_end); - ATF_TP_ADD_TC(tp, mempcpy_heap_before_end); - ATF_TP_ADD_TC(tp, mempcpy_heap_end); - ATF_TP_ADD_TC(tp, mempcpy_heap_after_end); - ATF_TP_ADD_TC(tp, memmove_before_end); - ATF_TP_ADD_TC(tp, memmove_end); - ATF_TP_ADD_TC(tp, memmove_heap_before_end); - ATF_TP_ADD_TC(tp, memmove_heap_end); - ATF_TP_ADD_TC(tp, memmove_heap_after_end); - ATF_TP_ADD_TC(tp, memset_before_end); - ATF_TP_ADD_TC(tp, memset_end); - ATF_TP_ADD_TC(tp, memset_heap_before_end); - ATF_TP_ADD_TC(tp, memset_heap_end); - ATF_TP_ADD_TC(tp, memset_heap_after_end); - ATF_TP_ADD_TC(tp, stpcpy_before_end); - ATF_TP_ADD_TC(tp, stpcpy_end); - ATF_TP_ADD_TC(tp, stpcpy_heap_before_end); - ATF_TP_ADD_TC(tp, stpcpy_heap_end); - ATF_TP_ADD_TC(tp, stpcpy_heap_after_end); - ATF_TP_ADD_TC(tp, stpncpy_before_end); - ATF_TP_ADD_TC(tp, stpncpy_end); - ATF_TP_ADD_TC(tp, stpncpy_heap_before_end); - ATF_TP_ADD_TC(tp, stpncpy_heap_end); - ATF_TP_ADD_TC(tp, stpncpy_heap_after_end); - ATF_TP_ADD_TC(tp, strcat_before_end); - ATF_TP_ADD_TC(tp, strcat_end); - ATF_TP_ADD_TC(tp, strcat_heap_before_end); - ATF_TP_ADD_TC(tp, strcat_heap_end); - ATF_TP_ADD_TC(tp, strcat_heap_after_end); - ATF_TP_ADD_TC(tp, strlcat_before_end); - ATF_TP_ADD_TC(tp, strlcat_end); - ATF_TP_ADD_TC(tp, strlcat_heap_before_end); - ATF_TP_ADD_TC(tp, strlcat_heap_end); - ATF_TP_ADD_TC(tp, strlcat_heap_after_end); - ATF_TP_ADD_TC(tp, strncat_before_end); - ATF_TP_ADD_TC(tp, strncat_end); - ATF_TP_ADD_TC(tp, strncat_heap_before_end); - ATF_TP_ADD_TC(tp, strncat_heap_end); - ATF_TP_ADD_TC(tp, strncat_heap_after_end); - ATF_TP_ADD_TC(tp, strcpy_before_end); - ATF_TP_ADD_TC(tp, strcpy_end); - ATF_TP_ADD_TC(tp, strcpy_heap_before_end); - ATF_TP_ADD_TC(tp, strcpy_heap_end); - ATF_TP_ADD_TC(tp, strcpy_heap_after_end); - ATF_TP_ADD_TC(tp, strlcpy_before_end); - ATF_TP_ADD_TC(tp, strlcpy_end); - ATF_TP_ADD_TC(tp, strlcpy_heap_before_end); - ATF_TP_ADD_TC(tp, strlcpy_heap_end); - ATF_TP_ADD_TC(tp, strlcpy_heap_after_end); - ATF_TP_ADD_TC(tp, strncpy_before_end); - ATF_TP_ADD_TC(tp, strncpy_end); - ATF_TP_ADD_TC(tp, strncpy_heap_before_end); - ATF_TP_ADD_TC(tp, strncpy_heap_end); - ATF_TP_ADD_TC(tp, strncpy_heap_after_end); + ATF_TP_ADD_TC(tp, wmemcpy_before_end); + ATF_TP_ADD_TC(tp, wmemcpy_end); + ATF_TP_ADD_TC(tp, wmemcpy_heap_before_end); + ATF_TP_ADD_TC(tp, wmemcpy_heap_end); + ATF_TP_ADD_TC(tp, wmemcpy_heap_after_end); + ATF_TP_ADD_TC(tp, wmempcpy_before_end); + ATF_TP_ADD_TC(tp, wmempcpy_end); + ATF_TP_ADD_TC(tp, wmempcpy_heap_before_end); + ATF_TP_ADD_TC(tp, wmempcpy_heap_end); + ATF_TP_ADD_TC(tp, wmempcpy_heap_after_end); + ATF_TP_ADD_TC(tp, wmemmove_before_end); + ATF_TP_ADD_TC(tp, wmemmove_end); + ATF_TP_ADD_TC(tp, wmemmove_heap_before_end); + ATF_TP_ADD_TC(tp, wmemmove_heap_end); + ATF_TP_ADD_TC(tp, wmemmove_heap_after_end); + ATF_TP_ADD_TC(tp, wmemset_before_end); + ATF_TP_ADD_TC(tp, wmemset_end); + ATF_TP_ADD_TC(tp, wmemset_heap_before_end); + ATF_TP_ADD_TC(tp, wmemset_heap_end); + ATF_TP_ADD_TC(tp, wmemset_heap_after_end); + ATF_TP_ADD_TC(tp, wcpcpy_before_end); + ATF_TP_ADD_TC(tp, wcpcpy_end); + ATF_TP_ADD_TC(tp, wcpcpy_heap_before_end); + ATF_TP_ADD_TC(tp, wcpcpy_heap_end); + ATF_TP_ADD_TC(tp, wcpcpy_heap_after_end); + ATF_TP_ADD_TC(tp, wcpncpy_before_end); + ATF_TP_ADD_TC(tp, wcpncpy_end); + ATF_TP_ADD_TC(tp, wcpncpy_heap_before_end); + ATF_TP_ADD_TC(tp, wcpncpy_heap_end); + ATF_TP_ADD_TC(tp, wcpncpy_heap_after_end); + ATF_TP_ADD_TC(tp, wcscat_before_end); + ATF_TP_ADD_TC(tp, wcscat_end); + ATF_TP_ADD_TC(tp, wcscat_heap_before_end); + ATF_TP_ADD_TC(tp, wcscat_heap_end); + ATF_TP_ADD_TC(tp, wcscat_heap_after_end); + ATF_TP_ADD_TC(tp, wcslcat_before_end); + ATF_TP_ADD_TC(tp, wcslcat_end); + ATF_TP_ADD_TC(tp, wcslcat_heap_before_end); + ATF_TP_ADD_TC(tp, wcslcat_heap_end); + ATF_TP_ADD_TC(tp, wcslcat_heap_after_end); + ATF_TP_ADD_TC(tp, wcsncat_before_end); + ATF_TP_ADD_TC(tp, wcsncat_end); + ATF_TP_ADD_TC(tp, wcsncat_heap_before_end); + ATF_TP_ADD_TC(tp, wcsncat_heap_end); + ATF_TP_ADD_TC(tp, wcsncat_heap_after_end); + ATF_TP_ADD_TC(tp, wcscpy_before_end); + ATF_TP_ADD_TC(tp, wcscpy_end); + ATF_TP_ADD_TC(tp, wcscpy_heap_before_end); + ATF_TP_ADD_TC(tp, wcscpy_heap_end); + ATF_TP_ADD_TC(tp, wcscpy_heap_after_end); + ATF_TP_ADD_TC(tp, wcslcpy_before_end); + ATF_TP_ADD_TC(tp, wcslcpy_end); + ATF_TP_ADD_TC(tp, wcslcpy_heap_before_end); + ATF_TP_ADD_TC(tp, wcslcpy_heap_end); + ATF_TP_ADD_TC(tp, wcslcpy_heap_after_end); + ATF_TP_ADD_TC(tp, wcsncpy_before_end); + ATF_TP_ADD_TC(tp, wcsncpy_end); + ATF_TP_ADD_TC(tp, wcsncpy_heap_before_end); + ATF_TP_ADD_TC(tp, wcsncpy_heap_end); + ATF_TP_ADD_TC(tp, wcsncpy_heap_after_end); return (atf_no_error()); } diff --git a/lib/libc/tests/secure/generate-fortify-tests.lua b/lib/libc/tests/secure/generate-fortify-tests.lua --- a/lib/libc/tests/secure/generate-fortify-tests.lua +++ b/lib/libc/tests/secure/generate-fortify-tests.lua @@ -77,6 +77,7 @@ "strings.h", "sysexits.h", "unistd.h", + "wchar.h", "atf-c.h", } @@ -114,6 +115,13 @@ src[__len - 1] = '\0'; ]] +local wstring_stackvars = "\twchar_t src[__len];\n" +local wstring_init = [[ + wmemset(__stack.__buf, 0, __len); + wmemset(src, 'A', __len - 1); + src[__len - 1] = '\0'; +]] + -- Each test entry describes how to test a given function. We need to know how -- to construct the buffer, we need to know the argument set we're dealing with, -- and we need to know what we're passing to each argument. We could be passing @@ -606,6 +614,148 @@ ]] }, }, + wchar = { + -- + { + func = "wmemcpy", + buftype = "wchar_t[]", + arguments = { + "__buf", + "src", + "__len", + }, + exclude = excludes_stack_overflow, + stackvars = "\twchar_t src[__len + 10];\n", + }, + { + func = "wmempcpy", + buftype = "wchar_t[]", + arguments = { + "__buf", + "src", + "__len", + }, + exclude = excludes_stack_overflow, + stackvars = "\twchar_t src[__len + 10];\n", + }, + { + func = "wmemmove", + buftype = "wchar_t[]", + arguments = { + "__buf", + "src", + "__len", + }, + exclude = excludes_stack_overflow, + stackvars = "\twchar_t src[__len + 10];\n", + }, + { + func = "wmemset", + buftype = "wchar_t[]", + arguments = { + "__buf", + "L'0'", + "__len", + }, + exclude = excludes_stack_overflow, + }, + { + func = "wcpcpy", + buftype = "wchar_t[]", + arguments = { + "__buf", + "src", + }, + exclude = excludes_stack_overflow, + stackvars = wstring_stackvars, + init = wstring_init, + uses_len = true, + }, + { + func = "wcpncpy", + buftype = "wchar_t[]", + arguments = { + "__buf", + "src", + "__len", + }, + exclude = excludes_stack_overflow, + stackvars = wstring_stackvars, + init = wstring_init, + }, + { + func = "wcscat", + buftype = "wchar_t[]", + arguments = { + "__buf", + "src", + }, + exclude = excludes_stack_overflow, + stackvars = wstring_stackvars, + init = wstring_init, + uses_len = true, + }, + { + func = "wcslcat", + buftype = "wchar_t[]", + arguments = { + "__buf", + "src", + "__len", + }, + exclude = excludes_stack_overflow, + stackvars = wstring_stackvars, + init = wstring_init, + }, + { + func = "wcsncat", + buftype = "wchar_t[]", + arguments = { + "__buf", + "src", + "__len", + }, + exclude = excludes_stack_overflow, + stackvars = wstring_stackvars, + init = wstring_init, + }, + { + func = "wcscpy", + buftype = "wchar_t[]", + arguments = { + "__buf", + "src", + }, + exclude = excludes_stack_overflow, + stackvars = wstring_stackvars, + init = wstring_init, + uses_len = true, + }, + { + func = "wcslcpy", + buftype = "wchar_t[]", + arguments = { + "__buf", + "src", + "__len", + }, + exclude = excludes_stack_overflow, + stackvars = wstring_stackvars, + init = wstring_init, + }, + { + func = "wcsncpy", + buftype = "wchar_t[]", + arguments = { + "__buf", + "src", + "__len", + }, + exclude = excludes_stack_overflow, + stackvars = wstring_stackvars, + init = wstring_init, + }, + }, } local function write_test_boilerplate(fh, name, body)