From 114b563adc2b942bc5abd4c5820507076d453f64 Mon Sep 17 00:00:00 2001 From: jvoisin Date: Mon, 2 Sep 2024 16:08:38 +0200 Subject: Revert d2594298b89d0fb8989cae3ebc8900e77b6aa478 As reported on irc: ``` 17:51 jvoisin, fortify-headers seems to be broken (on Alpine at least) 17:52 Repeating the message from over-there: 17:52 /usr/include/fortify/string.h: In function 'strncat': 17:52 /usr/include/fortify/string.h:297:36: error: implicit declaration of function 'strnlen'; did you mean 'strlen'? [-Wimplicit-function-declaration] 17:52 This is with a simple file that includes string.h and call strncat, built with c99 -O1 f.c ``` --- include/string.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/include/string.h b/include/string.h index 10d071a..c1c24bc 100644 --- a/include/string.h +++ b/include/string.h @@ -208,7 +208,9 @@ _FORTIFY_FN(stpncpy) char *stpncpy(char * _FORTIFY_POS0 __d, const char *__s, #if __has_builtin(__builtin___stpncpy_chk) && FORTIFY_USE_NATIVE_CHK return __builtin___stpncpy_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(); -- cgit v1.3