commit 6573631a5e4339a2fc2f86680e36e35e25bf416c
parent 60202fb5b50f3e56bf82f3424360377a29e25709
Author: Quentin Rameau <quinq@fifth.space>
Date: Wed, 2 Oct 2024 21:15:12 +0200
Fix usage of strnlen
As with previous commit, some strnlen calls
where introduced in 22a8094, but not reverted.
As strnlen isn't part of C standard,
this was breaking C builds.
Diffstat:
1 file changed, 6 insertions(+), 2 deletions(-)
diff --git a/include/string.h b/include/string.h
@@ -296,7 +296,9 @@ _FORTIFY_FN(strncat) char *strncat(char * _FORTIFY_POS0 __d, const char *__s,
__fh_size_t __b = __fh_bos(__d, 0);
if (__n > __b) {
- __fh_size_t __sl = strnlen(__s, __n);
+ __fh_size_t __sl = strlen(__s);
+ if (__sl > __n)
+ __sl = __n;
__fh_size_t __dl = strlen(__d);
if (__sl + __dl + 1 > __b)
__builtin_trap();
@@ -316,7 +318,9 @@ _FORTIFY_FN(strncpy) char *strncpy(char * _FORTIFY_POS0 __d,
#if __has_builtin(__builtin___strncpy_chk) && FORTIFY_USE_NATIVE_CHK
return __builtin___strncpy_chk(__d, __s, __n, __fh_bos(__d, 0));
#else
- __fh_size_t max_len_s = strnlen(__s, __n);
+ __fh_size_t max_len_s = strlen(__s);
+ if (max_len_s > __n)
+ max_len_s = __n;
if (__fh_overlap(__d, max_len_s, __s, max_len_s))
__builtin_trap();