1
0
mirror of https://sourceware.org/git/glibc.git synced 2025-07-29 11:41:21 +03:00

nonstring: Enable __FORTIFY_LEVEL=3

Use __builtin_dynamic_object_size in the remaining functions that
don't have compiler builtins as is the case for string functions.
This commit is contained in:
Siddhesh Poyarekar
2020-12-15 23:50:09 +05:30
parent 2a3224c536
commit f9de8bfe1a
7 changed files with 229 additions and 183 deletions

View File

@ -36,13 +36,14 @@ extern char *__REDIRECT_NTH (__realpath_chk_warn,
__fortify_function __wur char *
__NTH (realpath (const char *__restrict __name, char *__restrict __resolved))
{
if (__bos (__resolved) != (size_t) -1)
if (__glibc_objsize (__resolved) != (size_t) -1)
{
#if defined _LIBC_LIMITS_H_ && defined PATH_MAX
if (__bos (__resolved) < PATH_MAX)
return __realpath_chk_warn (__name, __resolved, __bos (__resolved));
if (__glibc_objsize (__resolved) < PATH_MAX)
return __realpath_chk_warn (__name, __resolved,
__glibc_objsize (__resolved));
#endif
return __realpath_chk (__name, __resolved, __bos (__resolved));
return __realpath_chk (__name, __resolved, __glibc_objsize (__resolved));
}
return __realpath_alias (__name, __resolved);
@ -64,12 +65,14 @@ extern int __REDIRECT_NTH (__ptsname_r_chk_warn,
__fortify_function int
__NTH (ptsname_r (int __fd, char *__buf, size_t __buflen))
{
if (__bos (__buf) != (size_t) -1)
if (__glibc_objsize (__buf) != (size_t) -1)
{
if (!__builtin_constant_p (__buflen))
return __ptsname_r_chk (__fd, __buf, __buflen, __bos (__buf));
if (__buflen > __bos (__buf))
return __ptsname_r_chk_warn (__fd, __buf, __buflen, __bos (__buf));
return __ptsname_r_chk (__fd, __buf, __buflen,
__glibc_objsize (__buf));
if (__buflen > __glibc_objsize (__buf))
return __ptsname_r_chk_warn (__fd, __buf, __buflen,
__glibc_objsize (__buf));
}
return __ptsname_r_alias (__fd, __buf, __buflen);
}
@ -90,8 +93,9 @@ __NTH (wctomb (char *__s, wchar_t __wchar))
#if defined MB_LEN_MAX && MB_LEN_MAX != __STDLIB_MB_LEN_MAX
# error "Assumed value of MB_LEN_MAX wrong"
#endif
if (__bos (__s) != (size_t) -1 && __STDLIB_MB_LEN_MAX > __bos (__s))
return __wctomb_chk (__s, __wchar, __bos (__s));
if (__glibc_objsize (__s) != (size_t) -1
&& __STDLIB_MB_LEN_MAX > __glibc_objsize (__s))
return __wctomb_chk (__s, __wchar, __glibc_objsize (__s));
return __wctomb_alias (__s, __wchar);
}
@ -116,15 +120,16 @@ __fortify_function size_t
__NTH (mbstowcs (wchar_t *__restrict __dst, const char *__restrict __src,
size_t __len))
{
if (__bos (__dst) != (size_t) -1)
if (__glibc_objsize (__dst) != (size_t) -1)
{
if (!__builtin_constant_p (__len))
return __mbstowcs_chk (__dst, __src, __len,
__bos (__dst) / sizeof (wchar_t));
__glibc_objsize (__dst) / sizeof (wchar_t));
if (__len > __bos (__dst) / sizeof (wchar_t))
if (__len > __glibc_objsize (__dst) / sizeof (wchar_t))
return __mbstowcs_chk_warn (__dst, __src, __len,
__bos (__dst) / sizeof (wchar_t));
(__glibc_objsize (__dst)
/ sizeof (wchar_t)));
}
return __mbstowcs_alias (__dst, __src, __len);
}
@ -149,12 +154,13 @@ __fortify_function size_t
__NTH (wcstombs (char *__restrict __dst, const wchar_t *__restrict __src,
size_t __len))
{
if (__bos (__dst) != (size_t) -1)
if (__glibc_objsize (__dst) != (size_t) -1)
{
if (!__builtin_constant_p (__len))
return __wcstombs_chk (__dst, __src, __len, __bos (__dst));
if (__len > __bos (__dst))
return __wcstombs_chk_warn (__dst, __src, __len, __bos (__dst));
return __wcstombs_chk (__dst, __src, __len, __glibc_objsize (__dst));
if (__len > __glibc_objsize (__dst))
return __wcstombs_chk_warn (__dst, __src, __len,
__glibc_objsize (__dst));
}
return __wcstombs_alias (__dst, __src, __len);
}