aboutsummaryrefslogtreecommitdiff
path: root/string
diff options
context:
space:
mode:
authorAdhemerval Zanella <adhemerval.zanella@linaro.org>2024-02-08 15:46:15 -0300
committerAdhemerval Zanella <adhemerval.zanella@linaro.org>2024-02-27 10:52:58 -0300
commit5e9696b26540d02639e0d16532e0f3d53c7e5cd0 (patch)
tree2e21d7f7fc0e73d4e2a9c81e6ed1f4e21206549d /string
parent29951991f5db1001c059f8ed7afa2c359cdc7f44 (diff)
downloadglibc-5e9696b26540d02639e0d16532e0f3d53c7e5cd0.zip
glibc-5e9696b26540d02639e0d16532e0f3d53c7e5cd0.tar.gz
glibc-5e9696b26540d02639e0d16532e0f3d53c7e5cd0.tar.bz2
string: Improve fortify with clang
It improve fortify checks for strcpy, stpcpy, strncpy, stpncpy, strcat, strncat, strlcpy, and strlcat. The runtime and compile checks have similar coverage as with GCC. Checked on aarch64, armhf, x86_64, and i686. Reviewed-by: Carlos O'Donell <carlos@redhat.com> Tested-by: Carlos O'Donell <carlos@redhat.com>
Diffstat (limited to 'string')
-rw-r--r--string/bits/string_fortified.h56
1 files changed, 34 insertions, 22 deletions
diff --git a/string/bits/string_fortified.h b/string/bits/string_fortified.h
index e0714f7..5c93dd6 100644
--- a/string/bits/string_fortified.h
+++ b/string/bits/string_fortified.h
@@ -73,24 +73,29 @@ __NTH (explicit_bzero (void *__dest, size_t __len))
}
#endif
-__fortify_function char *
-__NTH (strcpy (char *__restrict __dest, const char *__restrict __src))
+__fortify_function __attribute_overloadable__ char *
+__NTH (strcpy (__fortify_clang_overload_arg (char *, __restrict, __dest),
+ const char *__restrict __src))
+ __fortify_clang_warn_if_src_too_large (__dest, __src)
{
return __builtin___strcpy_chk (__dest, __src, __glibc_objsize (__dest));
}
#ifdef __USE_XOPEN2K8
-__fortify_function char *
-__NTH (stpcpy (char *__restrict __dest, const char *__restrict __src))
+__fortify_function __attribute_overloadable__ char *
+__NTH (stpcpy (__fortify_clang_overload_arg (char *, __restrict, __dest),
+ const char *__restrict __src))
+ __fortify_clang_warn_if_src_too_large (__dest, __src)
{
return __builtin___stpcpy_chk (__dest, __src, __glibc_objsize (__dest));
}
#endif
-__fortify_function char *
-__NTH (strncpy (char *__restrict __dest, const char *__restrict __src,
- size_t __len))
+__fortify_function __attribute_overloadable__ char *
+__NTH (strncpy (__fortify_clang_overload_arg (char *, __restrict, __dest),
+ const char *__restrict __src, size_t __len))
+ __fortify_clang_warn_if_dest_too_small (__dest, __len)
{
return __builtin___strncpy_chk (__dest, __src, __len,
__glibc_objsize (__dest));
@@ -98,8 +103,10 @@ __NTH (strncpy (char *__restrict __dest, const char *__restrict __src,
#ifdef __USE_XOPEN2K8
# if __GNUC_PREREQ (4, 7) || __glibc_clang_prereq (2, 6)
-__fortify_function char *
-__NTH (stpncpy (char *__dest, const char *__src, size_t __n))
+__fortify_function __attribute_overloadable__ char *
+__NTH (stpncpy (__fortify_clang_overload_arg (char *, ,__dest),
+ const char *__src, size_t __n))
+ __fortify_clang_warn_if_dest_too_small (__dest, __n)
{
return __builtin___stpncpy_chk (__dest, __src, __n,
__glibc_objsize (__dest));
@@ -112,8 +119,9 @@ extern char *__stpncpy_chk (char *__dest, const char *__src, size_t __n,
extern char *__REDIRECT_NTH (__stpncpy_alias, (char *__dest, const char *__src,
size_t __n), stpncpy);
-__fortify_function char *
-__NTH (stpncpy (char *__dest, const char *__src, size_t __n))
+__fortify_function __attribute_overloadable__ char *
+__NTH (stpncpy (__fortify_clang_overload_arg (char *, ,__dest),
+ const char *__src, size_t __n))
{
if (__bos (__dest) != (size_t) -1
&& (!__builtin_constant_p (__n) || __n > __bos (__dest)))
@@ -124,16 +132,19 @@ __NTH (stpncpy (char *__dest, const char *__src, size_t __n))
#endif
-__fortify_function char *
-__NTH (strcat (char *__restrict __dest, const char *__restrict __src))
+__fortify_function __attribute_overloadable__ char *
+__NTH (strcat (__fortify_clang_overload_arg (char *, __restrict, __dest),
+ const char *__restrict __src))
+ __fortify_clang_warn_if_src_too_large (__dest, __src)
{
return __builtin___strcat_chk (__dest, __src, __glibc_objsize (__dest));
}
-__fortify_function char *
-__NTH (strncat (char *__restrict __dest, const char *__restrict __src,
- size_t __len))
+__fortify_function __attribute_overloadable__ char *
+__NTH (strncat (__fortify_clang_overload_arg (char *, __restrict, __dest),
+ const char *__restrict __src, size_t __len))
+ __fortify_clang_warn_if_src_too_large (__dest, __src)
{
return __builtin___strncat_chk (__dest, __src, __len,
__glibc_objsize (__dest));
@@ -146,9 +157,10 @@ extern size_t __REDIRECT_NTH (__strlcpy_alias,
(char *__dest, const char *__src, size_t __n),
strlcpy);
-__fortify_function size_t
-__NTH (strlcpy (char *__restrict __dest, const char *__restrict __src,
- size_t __n))
+__fortify_function __attribute_overloadable__ size_t
+__NTH (strlcpy (__fortify_clang_overload_arg (char *, __restrict, __dest),
+ const char *__restrict __src, size_t __n))
+ __fortify_clang_warn_if_dest_too_small (__dest, __n)
{
if (__glibc_objsize (__dest) != (size_t) -1
&& (!__builtin_constant_p (__n > __glibc_objsize (__dest))
@@ -163,9 +175,9 @@ extern size_t __REDIRECT_NTH (__strlcat_alias,
(char *__dest, const char *__src, size_t __n),
strlcat);
-__fortify_function size_t
-__NTH (strlcat (char *__restrict __dest, const char *__restrict __src,
- size_t __n))
+__fortify_function __attribute_overloadable__ size_t
+__NTH (strlcat (__fortify_clang_overload_arg (char *, __restrict, __dest),
+ const char *__restrict __src, size_t __n))
{
if (__glibc_objsize (__dest) != (size_t) -1
&& (!__builtin_constant_p (__n > __glibc_objsize (__dest))