2015-05-13 11:15:36 +00:00
|
|
|
/*
|
2017-08-22 10:31:49 +00:00
|
|
|
* Copyright (C) 2015-2017 Dimitris Papastamos <sin@2f30.org>
|
2015-05-13 11:15:36 +00:00
|
|
|
*
|
|
|
|
* Permission to use, copy, modify, and/or distribute this software for any
|
|
|
|
* purpose with or without fee is hereby granted.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
|
|
|
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
|
|
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
|
|
|
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
|
|
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
|
|
|
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
|
|
|
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
|
|
*/
|
|
|
|
|
2015-03-11 18:55:51 +00:00
|
|
|
#ifndef _FORTIFY_WCHAR_H
|
|
|
|
#define _FORTIFY_WCHAR_H
|
2015-03-03 14:34:35 +00:00
|
|
|
|
Don't use __extension__ in C++ code
A few important notes:
* __extension__ is a GNU C "alternate" keyword, not a C++ keyword.[1]
* __extension__ is designed to work on "expressions"; it does work on
#include_next in C mode, but it has no effect in C++ mode; the
warning will still appear, if enabled, even with __extension__
preceding #include_next. This is because #include_next is not
considered an expression in C++, so the compiler attaches
__extension__ to the first expression of the header.
All of this leads us to a build failure while building at least all
Mozilla software. Moz has an alternate -isystem dir searched before
/usr/include that overrides some headers, including <features.h>. The
first statement in each of these headers is a #pragma, and since
__extension__ is looking for an expression, and #pragma is a "null"
expression, we end up with the following error:
dist/system_wrappers/features.h:1:9: error: '#pragma' is not allowed here
Since __extension__ has no effect on #include_next in C++ mode anyway,
and since it can cause breakage, this commit omits __extension__ in C++
mode.
[1]: https://gcc.gnu.org/onlinedocs/gcc-6.4.0/gcc/Alternate-Keywords.html
2018-06-23 22:57:48 +00:00
|
|
|
#ifndef __cplusplus
|
2015-07-15 14:53:41 +00:00
|
|
|
__extension__
|
Don't use __extension__ in C++ code
A few important notes:
* __extension__ is a GNU C "alternate" keyword, not a C++ keyword.[1]
* __extension__ is designed to work on "expressions"; it does work on
#include_next in C mode, but it has no effect in C++ mode; the
warning will still appear, if enabled, even with __extension__
preceding #include_next. This is because #include_next is not
considered an expression in C++, so the compiler attaches
__extension__ to the first expression of the header.
All of this leads us to a build failure while building at least all
Mozilla software. Moz has an alternate -isystem dir searched before
/usr/include that overrides some headers, including <features.h>. The
first statement in each of these headers is a #pragma, and since
__extension__ is looking for an expression, and #pragma is a "null"
expression, we end up with the following error:
dist/system_wrappers/features.h:1:9: error: '#pragma' is not allowed here
Since __extension__ has no effect on #include_next in C++ mode anyway,
and since it can cause breakage, this commit omits __extension__ in C++
mode.
[1]: https://gcc.gnu.org/onlinedocs/gcc-6.4.0/gcc/Alternate-Keywords.html
2018-06-23 22:57:48 +00:00
|
|
|
#endif
|
2015-07-15 14:53:41 +00:00
|
|
|
#include_next <limits.h>
|
Don't use __extension__ in C++ code
A few important notes:
* __extension__ is a GNU C "alternate" keyword, not a C++ keyword.[1]
* __extension__ is designed to work on "expressions"; it does work on
#include_next in C mode, but it has no effect in C++ mode; the
warning will still appear, if enabled, even with __extension__
preceding #include_next. This is because #include_next is not
considered an expression in C++, so the compiler attaches
__extension__ to the first expression of the header.
All of this leads us to a build failure while building at least all
Mozilla software. Moz has an alternate -isystem dir searched before
/usr/include that overrides some headers, including <features.h>. The
first statement in each of these headers is a #pragma, and since
__extension__ is looking for an expression, and #pragma is a "null"
expression, we end up with the following error:
dist/system_wrappers/features.h:1:9: error: '#pragma' is not allowed here
Since __extension__ has no effect on #include_next in C++ mode anyway,
and since it can cause breakage, this commit omits __extension__ in C++
mode.
[1]: https://gcc.gnu.org/onlinedocs/gcc-6.4.0/gcc/Alternate-Keywords.html
2018-06-23 22:57:48 +00:00
|
|
|
#ifndef __cplusplus
|
2015-06-24 18:13:37 +00:00
|
|
|
__extension__
|
Don't use __extension__ in C++ code
A few important notes:
* __extension__ is a GNU C "alternate" keyword, not a C++ keyword.[1]
* __extension__ is designed to work on "expressions"; it does work on
#include_next in C mode, but it has no effect in C++ mode; the
warning will still appear, if enabled, even with __extension__
preceding #include_next. This is because #include_next is not
considered an expression in C++, so the compiler attaches
__extension__ to the first expression of the header.
All of this leads us to a build failure while building at least all
Mozilla software. Moz has an alternate -isystem dir searched before
/usr/include that overrides some headers, including <features.h>. The
first statement in each of these headers is a #pragma, and since
__extension__ is looking for an expression, and #pragma is a "null"
expression, we end up with the following error:
dist/system_wrappers/features.h:1:9: error: '#pragma' is not allowed here
Since __extension__ has no effect on #include_next in C++ mode anyway,
and since it can cause breakage, this commit omits __extension__ in C++
mode.
[1]: https://gcc.gnu.org/onlinedocs/gcc-6.4.0/gcc/Alternate-Keywords.html
2018-06-23 22:57:48 +00:00
|
|
|
#endif
|
2015-03-04 12:27:04 +00:00
|
|
|
#include_next <stdlib.h>
|
Don't use __extension__ in C++ code
A few important notes:
* __extension__ is a GNU C "alternate" keyword, not a C++ keyword.[1]
* __extension__ is designed to work on "expressions"; it does work on
#include_next in C mode, but it has no effect in C++ mode; the
warning will still appear, if enabled, even with __extension__
preceding #include_next. This is because #include_next is not
considered an expression in C++, so the compiler attaches
__extension__ to the first expression of the header.
All of this leads us to a build failure while building at least all
Mozilla software. Moz has an alternate -isystem dir searched before
/usr/include that overrides some headers, including <features.h>. The
first statement in each of these headers is a #pragma, and since
__extension__ is looking for an expression, and #pragma is a "null"
expression, we end up with the following error:
dist/system_wrappers/features.h:1:9: error: '#pragma' is not allowed here
Since __extension__ has no effect on #include_next in C++ mode anyway,
and since it can cause breakage, this commit omits __extension__ in C++
mode.
[1]: https://gcc.gnu.org/onlinedocs/gcc-6.4.0/gcc/Alternate-Keywords.html
2018-06-23 22:57:48 +00:00
|
|
|
#ifndef __cplusplus
|
2015-06-24 18:13:37 +00:00
|
|
|
__extension__
|
Don't use __extension__ in C++ code
A few important notes:
* __extension__ is a GNU C "alternate" keyword, not a C++ keyword.[1]
* __extension__ is designed to work on "expressions"; it does work on
#include_next in C mode, but it has no effect in C++ mode; the
warning will still appear, if enabled, even with __extension__
preceding #include_next. This is because #include_next is not
considered an expression in C++, so the compiler attaches
__extension__ to the first expression of the header.
All of this leads us to a build failure while building at least all
Mozilla software. Moz has an alternate -isystem dir searched before
/usr/include that overrides some headers, including <features.h>. The
first statement in each of these headers is a #pragma, and since
__extension__ is looking for an expression, and #pragma is a "null"
expression, we end up with the following error:
dist/system_wrappers/features.h:1:9: error: '#pragma' is not allowed here
Since __extension__ has no effect on #include_next in C++ mode anyway,
and since it can cause breakage, this commit omits __extension__ in C++
mode.
[1]: https://gcc.gnu.org/onlinedocs/gcc-6.4.0/gcc/Alternate-Keywords.html
2018-06-23 22:57:48 +00:00
|
|
|
#endif
|
2015-07-15 14:53:41 +00:00
|
|
|
#include_next <string.h>
|
Don't use __extension__ in C++ code
A few important notes:
* __extension__ is a GNU C "alternate" keyword, not a C++ keyword.[1]
* __extension__ is designed to work on "expressions"; it does work on
#include_next in C mode, but it has no effect in C++ mode; the
warning will still appear, if enabled, even with __extension__
preceding #include_next. This is because #include_next is not
considered an expression in C++, so the compiler attaches
__extension__ to the first expression of the header.
All of this leads us to a build failure while building at least all
Mozilla software. Moz has an alternate -isystem dir searched before
/usr/include that overrides some headers, including <features.h>. The
first statement in each of these headers is a #pragma, and since
__extension__ is looking for an expression, and #pragma is a "null"
expression, we end up with the following error:
dist/system_wrappers/features.h:1:9: error: '#pragma' is not allowed here
Since __extension__ has no effect on #include_next in C++ mode anyway,
and since it can cause breakage, this commit omits __extension__ in C++
mode.
[1]: https://gcc.gnu.org/onlinedocs/gcc-6.4.0/gcc/Alternate-Keywords.html
2018-06-23 22:57:48 +00:00
|
|
|
#ifndef __cplusplus
|
2015-07-15 14:53:41 +00:00
|
|
|
__extension__
|
Don't use __extension__ in C++ code
A few important notes:
* __extension__ is a GNU C "alternate" keyword, not a C++ keyword.[1]
* __extension__ is designed to work on "expressions"; it does work on
#include_next in C mode, but it has no effect in C++ mode; the
warning will still appear, if enabled, even with __extension__
preceding #include_next. This is because #include_next is not
considered an expression in C++, so the compiler attaches
__extension__ to the first expression of the header.
All of this leads us to a build failure while building at least all
Mozilla software. Moz has an alternate -isystem dir searched before
/usr/include that overrides some headers, including <features.h>. The
first statement in each of these headers is a #pragma, and since
__extension__ is looking for an expression, and #pragma is a "null"
expression, we end up with the following error:
dist/system_wrappers/features.h:1:9: error: '#pragma' is not allowed here
Since __extension__ has no effect on #include_next in C++ mode anyway,
and since it can cause breakage, this commit omits __extension__ in C++
mode.
[1]: https://gcc.gnu.org/onlinedocs/gcc-6.4.0/gcc/Alternate-Keywords.html
2018-06-23 22:57:48 +00:00
|
|
|
#endif
|
2015-03-03 14:34:35 +00:00
|
|
|
#include_next <wchar.h>
|
|
|
|
|
|
|
|
#if defined(_FORTIFY_SOURCE) && _FORTIFY_SOURCE > 0 && defined(__OPTIMIZE__) && __OPTIMIZE__ > 0
|
2015-05-13 11:04:15 +00:00
|
|
|
#include "fortify-headers.h"
|
2015-03-03 14:34:35 +00:00
|
|
|
|
2015-03-13 23:09:15 +00:00
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
2015-03-13 11:00:46 +00:00
|
|
|
#undef fgetws
|
|
|
|
#undef mbsrtowcs
|
|
|
|
#undef mbstowcs
|
|
|
|
#undef wcrtomb
|
|
|
|
#undef wcscat
|
|
|
|
#undef wcscpy
|
|
|
|
#undef wcsncat
|
|
|
|
#undef wcsncpy
|
|
|
|
#undef wcsrtombs
|
|
|
|
#undef wcstombs
|
|
|
|
#undef wctomb
|
|
|
|
#undef wmemcpy
|
|
|
|
#undef wmemmove
|
|
|
|
#undef wmemset
|
2015-03-11 09:26:11 +00:00
|
|
|
|
2015-06-03 17:27:01 +00:00
|
|
|
_FORTIFY_FN(fgetws) wchar_t *fgetws(wchar_t *__s, int __n, FILE *__f)
|
2015-03-03 14:34:35 +00:00
|
|
|
{
|
2015-06-03 17:27:01 +00:00
|
|
|
size_t __b = __builtin_object_size(__s, 0);
|
2015-03-03 14:34:35 +00:00
|
|
|
|
2015-06-03 17:27:01 +00:00
|
|
|
if ((size_t)__n > __b / sizeof(wchar_t))
|
2015-03-03 14:34:35 +00:00
|
|
|
__builtin_trap();
|
2015-06-03 17:27:01 +00:00
|
|
|
return __orig_fgetws(__s, __n, __f);
|
2015-03-03 14:34:35 +00:00
|
|
|
}
|
|
|
|
|
2015-04-01 11:41:08 +00:00
|
|
|
#if defined(_POSIX_SOURCE) || defined(_POSIX_C_SOURCE) \
|
|
|
|
|| defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) || defined(_BSD_SOURCE)
|
|
|
|
#undef mbsnrtowcs
|
2015-06-03 17:27:01 +00:00
|
|
|
_FORTIFY_FN(mbsnrtowcs) size_t mbsnrtowcs(wchar_t *__d, const char **__s, size_t __n,
|
|
|
|
size_t __wn, mbstate_t *__st)
|
2015-03-03 20:30:47 +00:00
|
|
|
{
|
2015-06-03 17:27:01 +00:00
|
|
|
size_t __b = __builtin_object_size(__d, 0);
|
|
|
|
size_t __r;
|
2015-03-03 20:30:47 +00:00
|
|
|
|
2015-06-03 17:27:01 +00:00
|
|
|
if (__wn > __n / sizeof(wchar_t)) {
|
|
|
|
__b /= sizeof(wchar_t);
|
|
|
|
__r = __orig_mbsnrtowcs(__d, __s, __n, __wn > __b ? __b : __wn, __st);
|
|
|
|
if (__b < __wn && __d && *__s && __r != (size_t)-1)
|
2015-03-05 18:21:52 +00:00
|
|
|
__builtin_trap();
|
|
|
|
} else {
|
2015-06-03 17:27:01 +00:00
|
|
|
__r = __orig_mbsnrtowcs(__d, __s, __n > __b ? __b : __n, __wn, __st);
|
|
|
|
if (__b < __n && __d && *__s && __r != (size_t)-1)
|
2015-03-05 18:21:52 +00:00
|
|
|
__builtin_trap();
|
|
|
|
}
|
2015-06-03 17:27:01 +00:00
|
|
|
return __r;
|
2015-03-03 20:30:47 +00:00
|
|
|
}
|
2015-04-01 11:41:08 +00:00
|
|
|
#endif
|
2015-03-03 20:30:47 +00:00
|
|
|
|
2015-06-03 17:27:01 +00:00
|
|
|
_FORTIFY_FN(mbsrtowcs) size_t mbsrtowcs(wchar_t *__d, const char **__s, size_t __wn,
|
|
|
|
mbstate_t *__st)
|
2015-03-03 20:30:47 +00:00
|
|
|
{
|
2015-06-03 17:27:01 +00:00
|
|
|
size_t __b = __builtin_object_size(__d, 0);
|
|
|
|
size_t __r;
|
2015-03-03 20:30:47 +00:00
|
|
|
|
2015-06-03 17:27:01 +00:00
|
|
|
__b /= sizeof(wchar_t);
|
|
|
|
__r = __orig_mbsrtowcs(__d, __s, __wn > __b ? __b : __wn, __st);
|
|
|
|
if (__b < __wn && __d && *__s && __r != (size_t)-1)
|
2015-03-03 20:30:47 +00:00
|
|
|
__builtin_trap();
|
2015-06-03 17:27:01 +00:00
|
|
|
return __r;
|
2015-03-03 20:30:47 +00:00
|
|
|
}
|
|
|
|
|
2015-06-03 17:27:01 +00:00
|
|
|
_FORTIFY_FN(mbstowcs) size_t mbstowcs(wchar_t *__ws, const char *__s, size_t __wn)
|
2015-03-03 20:36:35 +00:00
|
|
|
{
|
2015-06-03 17:27:01 +00:00
|
|
|
size_t __b = __builtin_object_size(__ws, 0);
|
2015-03-03 20:36:35 +00:00
|
|
|
|
2015-06-03 17:27:01 +00:00
|
|
|
if (__ws && __wn > __b / sizeof(wchar_t))
|
2015-03-03 20:36:35 +00:00
|
|
|
__builtin_trap();
|
2015-06-03 17:27:01 +00:00
|
|
|
return __orig_mbstowcs(__ws, __s, __wn);
|
2015-03-03 20:36:35 +00:00
|
|
|
}
|
|
|
|
|
2015-06-03 17:27:01 +00:00
|
|
|
_FORTIFY_FN(wcrtomb) size_t wcrtomb(char *__s, wchar_t __w, mbstate_t *__st)
|
2015-03-04 12:27:04 +00:00
|
|
|
{
|
2019-03-06 13:28:48 +00:00
|
|
|
if (__s && MB_LEN_MAX > __builtin_object_size(__s, 2)) {
|
|
|
|
char __buf[MB_LEN_MAX];
|
|
|
|
size_t __r;
|
2015-03-04 12:27:04 +00:00
|
|
|
|
2015-07-15 14:53:41 +00:00
|
|
|
__r = __orig_wcrtomb(__buf, __w, __st);
|
2017-08-22 10:31:49 +00:00
|
|
|
if (__r == (size_t)-1)
|
|
|
|
return __r;
|
2019-03-06 13:28:48 +00:00
|
|
|
if (__r > __builtin_object_size(__s, 0))
|
2015-07-15 14:53:41 +00:00
|
|
|
__builtin_trap();
|
2019-02-25 13:01:12 +00:00
|
|
|
__builtin_memcpy(__s, __buf, __r);
|
2015-07-15 14:53:41 +00:00
|
|
|
return __r;
|
|
|
|
}
|
2015-06-03 17:27:01 +00:00
|
|
|
return __orig_wcrtomb(__s, __w, __st);
|
2015-03-04 12:27:04 +00:00
|
|
|
}
|
|
|
|
|
2015-06-03 17:27:01 +00:00
|
|
|
_FORTIFY_FN(wcscat) wchar_t *wcscat(wchar_t *__d, const wchar_t *__s)
|
2015-03-04 12:27:04 +00:00
|
|
|
{
|
2015-06-03 17:27:01 +00:00
|
|
|
size_t __b = __builtin_object_size(__d, 0);
|
2015-03-04 12:27:04 +00:00
|
|
|
|
2015-06-03 17:27:01 +00:00
|
|
|
if (wcslen(__s) + wcslen(__d) + 1 > __b / sizeof(wchar_t))
|
2015-03-04 12:27:04 +00:00
|
|
|
__builtin_trap();
|
2015-06-03 17:27:01 +00:00
|
|
|
return __orig_wcscat(__d, __s);
|
2015-03-04 12:27:04 +00:00
|
|
|
}
|
|
|
|
|
2015-06-03 17:27:01 +00:00
|
|
|
_FORTIFY_FN(wcscpy) wchar_t *wcscpy(wchar_t *__d, const wchar_t *__s)
|
2015-03-04 12:27:04 +00:00
|
|
|
{
|
2015-06-03 17:27:01 +00:00
|
|
|
size_t __b = __builtin_object_size(__d, 0);
|
2015-03-04 12:27:04 +00:00
|
|
|
|
2015-06-03 17:27:01 +00:00
|
|
|
if (wcslen(__s) + 1 > __b / sizeof(wchar_t))
|
2015-03-04 12:27:04 +00:00
|
|
|
__builtin_trap();
|
2015-06-03 17:27:01 +00:00
|
|
|
return __orig_wcscpy(__d, __s);
|
2015-03-04 12:27:04 +00:00
|
|
|
}
|
|
|
|
|
2015-06-03 17:27:01 +00:00
|
|
|
_FORTIFY_FN(wcsncat) wchar_t *wcsncat(wchar_t *__d, const wchar_t *__s, size_t __n)
|
2015-03-04 12:42:55 +00:00
|
|
|
{
|
2015-06-03 17:27:01 +00:00
|
|
|
size_t __b = __builtin_object_size(__d, 0);
|
|
|
|
size_t __sl, __dl;
|
2015-03-04 12:42:55 +00:00
|
|
|
|
2015-06-03 17:27:01 +00:00
|
|
|
if (__n > __b / sizeof(wchar_t)) {
|
|
|
|
__sl = wcslen(__s);
|
|
|
|
__dl = wcslen(__d);
|
|
|
|
if (__sl > __n)
|
|
|
|
__sl = __n;
|
|
|
|
if (__sl + __dl + 1 > __b / sizeof(wchar_t))
|
2015-03-04 12:42:55 +00:00
|
|
|
__builtin_trap();
|
|
|
|
}
|
2015-06-03 17:27:01 +00:00
|
|
|
return __orig_wcsncat(__d, __s, __n);
|
2015-03-04 12:42:55 +00:00
|
|
|
}
|
|
|
|
|
2015-06-03 17:27:01 +00:00
|
|
|
_FORTIFY_FN(wcsncpy) wchar_t *wcsncpy(wchar_t *__d, const wchar_t *__s, size_t __n)
|
2015-03-04 12:42:55 +00:00
|
|
|
{
|
2015-06-03 17:27:01 +00:00
|
|
|
size_t __b = __builtin_object_size(__d, 0);
|
2015-03-04 12:42:55 +00:00
|
|
|
|
2015-06-03 17:27:01 +00:00
|
|
|
if (__n > __b / sizeof(wchar_t))
|
2015-03-04 12:42:55 +00:00
|
|
|
__builtin_trap();
|
2015-06-03 17:27:01 +00:00
|
|
|
return __orig_wcsncpy(__d, __s, __n);
|
2015-03-04 12:42:55 +00:00
|
|
|
}
|
|
|
|
|
2015-04-01 11:41:08 +00:00
|
|
|
#if defined(_POSIX_SOURCE) || defined(_POSIX_C_SOURCE) \
|
|
|
|
|| defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) || defined(_BSD_SOURCE)
|
|
|
|
#undef wcsnrtombs
|
2015-06-03 17:27:01 +00:00
|
|
|
_FORTIFY_FN(wcsnrtombs) size_t wcsnrtombs(char *__d, const wchar_t **__s, size_t __wn,
|
|
|
|
size_t __n, mbstate_t *__st)
|
2015-03-04 12:59:41 +00:00
|
|
|
{
|
2015-06-03 17:27:01 +00:00
|
|
|
size_t __b = __builtin_object_size(__d, 0);
|
|
|
|
size_t __r;
|
2015-03-04 12:59:41 +00:00
|
|
|
|
2015-06-03 17:27:01 +00:00
|
|
|
if (__wn > __n / sizeof(wchar_t)) {
|
|
|
|
__b /= sizeof(wchar_t);
|
|
|
|
__r = __orig_wcsnrtombs(__d, __s, __wn > __b ? __b : __wn, __n, __st);
|
|
|
|
if (__b < __wn && __d && *__s && __r != (size_t)-1)
|
2015-03-05 18:21:52 +00:00
|
|
|
__builtin_trap();
|
|
|
|
} else {
|
2015-06-03 17:27:01 +00:00
|
|
|
__r = __orig_wcsnrtombs(__d, __s, __wn, __n > __b ? __b : __n, __st);
|
|
|
|
if (__b < __n && __d && *__s && __r != (size_t)-1)
|
2015-03-05 18:21:52 +00:00
|
|
|
__builtin_trap();
|
|
|
|
}
|
2015-06-03 17:27:01 +00:00
|
|
|
return __r;
|
2015-03-04 12:59:41 +00:00
|
|
|
}
|
2015-04-01 11:41:08 +00:00
|
|
|
#endif
|
2015-03-04 12:59:41 +00:00
|
|
|
|
2015-06-03 17:27:01 +00:00
|
|
|
_FORTIFY_FN(wcsrtombs) size_t wcsrtombs(char *__d, const wchar_t **__s, size_t __n,
|
|
|
|
mbstate_t *__st)
|
2015-03-04 12:59:41 +00:00
|
|
|
{
|
2015-06-03 17:27:01 +00:00
|
|
|
size_t __b = __builtin_object_size(__d, 0);
|
|
|
|
size_t __r;
|
2015-03-04 12:59:41 +00:00
|
|
|
|
2015-06-03 17:27:01 +00:00
|
|
|
__r = __orig_wcsrtombs(__d, __s, __n > __b ? __b : __n, __st);
|
|
|
|
if (__b < __n && __d && *__s && __r != (size_t)-1)
|
2015-03-04 12:59:41 +00:00
|
|
|
__builtin_trap();
|
2015-06-03 17:27:01 +00:00
|
|
|
return __r;
|
2015-03-04 12:59:41 +00:00
|
|
|
}
|
|
|
|
|
2015-06-03 17:27:01 +00:00
|
|
|
_FORTIFY_FN(wcstombs) size_t wcstombs(char *__s, const wchar_t *__ws, size_t __n)
|
2015-03-04 13:09:31 +00:00
|
|
|
{
|
2015-06-03 17:27:01 +00:00
|
|
|
size_t __b = __builtin_object_size(__s, 0);
|
2015-03-04 13:09:31 +00:00
|
|
|
|
2015-06-03 17:27:01 +00:00
|
|
|
if (__s && __n > __b)
|
2015-03-04 13:09:31 +00:00
|
|
|
__builtin_trap();
|
2015-06-03 17:27:01 +00:00
|
|
|
return __orig_wcstombs(__s, __ws, __n);
|
2015-03-04 13:09:31 +00:00
|
|
|
}
|
|
|
|
|
2015-06-03 17:27:01 +00:00
|
|
|
_FORTIFY_FN(wctomb) int wctomb(char *__s, wchar_t __w)
|
2015-03-04 13:12:58 +00:00
|
|
|
{
|
2015-06-03 17:27:01 +00:00
|
|
|
size_t __b = __builtin_object_size(__s, 0);
|
2015-03-04 13:12:58 +00:00
|
|
|
|
2019-03-06 13:28:48 +00:00
|
|
|
if (__s && MB_LEN_MAX > __b && MB_CUR_MAX > __b)
|
2015-03-04 13:12:58 +00:00
|
|
|
__builtin_trap();
|
2015-06-03 17:27:01 +00:00
|
|
|
return __orig_wctomb(__s, __w);
|
2015-03-04 13:12:58 +00:00
|
|
|
}
|
|
|
|
|
2015-06-03 17:27:01 +00:00
|
|
|
_FORTIFY_FN(wmemcpy) wchar_t *wmemcpy(wchar_t *__d, const wchar_t *__s, size_t __n)
|
2015-03-03 18:16:29 +00:00
|
|
|
{
|
2015-06-03 17:27:01 +00:00
|
|
|
size_t __b = __builtin_object_size(__d, 0);
|
2015-03-03 18:16:29 +00:00
|
|
|
|
2015-06-03 17:27:01 +00:00
|
|
|
if (__n > __b / sizeof(wchar_t))
|
2015-03-03 18:16:29 +00:00
|
|
|
__builtin_trap();
|
2015-06-03 17:27:01 +00:00
|
|
|
return __orig_wmemcpy(__d, __s, __n);
|
2015-03-03 18:16:29 +00:00
|
|
|
}
|
|
|
|
|
2015-06-03 17:27:01 +00:00
|
|
|
_FORTIFY_FN(wmemmove) wchar_t *wmemmove(wchar_t *__d, const wchar_t *__s, size_t __n)
|
2015-03-03 18:16:29 +00:00
|
|
|
{
|
2015-06-03 17:27:01 +00:00
|
|
|
size_t __b = __builtin_object_size(__d, 0);
|
2015-03-03 18:16:29 +00:00
|
|
|
|
2015-06-03 17:27:01 +00:00
|
|
|
if (__n > __b / sizeof(wchar_t))
|
2015-03-03 18:16:29 +00:00
|
|
|
__builtin_trap();
|
2015-06-03 17:27:01 +00:00
|
|
|
return __orig_wmemmove(__d, __s, __n);
|
2015-03-03 18:16:29 +00:00
|
|
|
}
|
|
|
|
|
2015-06-03 17:27:01 +00:00
|
|
|
_FORTIFY_FN(wmemset) wchar_t *wmemset(wchar_t *__s, wchar_t __c, size_t __n)
|
2015-03-03 18:13:14 +00:00
|
|
|
{
|
2015-06-03 17:27:01 +00:00
|
|
|
size_t __b = __builtin_object_size(__s, 0);
|
2015-03-03 18:13:14 +00:00
|
|
|
|
2015-06-03 17:27:01 +00:00
|
|
|
if (__n > __b / sizeof(wchar_t))
|
2015-03-03 18:13:14 +00:00
|
|
|
__builtin_trap();
|
2015-06-03 17:27:01 +00:00
|
|
|
return __orig_wmemset(__s, __c, __n);
|
2015-03-03 18:13:14 +00:00
|
|
|
}
|
|
|
|
|
2015-03-13 23:09:15 +00:00
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
2015-03-11 09:26:11 +00:00
|
|
|
#endif
|
|
|
|
|
2015-03-03 14:34:35 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#endif
|