summaryrefslogtreecommitdiff
path: root/include/string.h
diff options
context:
space:
mode:
authorjvoisin2023-12-27 12:36:47 +0100
committerJulien Voisin2023-12-27 16:06:59 +0100
commit80a83a56b52e833e6d3afec4d0723d7625d52cee (patch)
treed8b0c2930b867f2eb1867f3f362b64dac84ce3ac /include/string.h
parent01dc0e38a8a0be034bf21cc6ae4cc8cebc0e7a79 (diff)
Don't check for overlapping in strncpy/stpncpy for now
They check overlap across the whole range of the given length, but the given length is not what will actually be copied, rather it's the maximum length (if src is shorter, only length of src will be copied). This triggers false positives and traps where it shouldn't (e.g. in ICU tests). Reported-by: q66
Diffstat (limited to 'include/string.h')
-rw-r--r--include/string.h14
1 files changed, 14 insertions, 0 deletions
diff --git a/include/string.h b/include/string.h
index 778d22a..925e572 100644
--- a/include/string.h
+++ b/include/string.h
@@ -189,8 +189,15 @@ _FORTIFY_FN(stpncpy) char *stpncpy(char * _FORTIFY_POS0 __d, const char *__s,
189#if __has_builtin(__builtin___stpncpy_chk) && USE_NATIVE_CHK 189#if __has_builtin(__builtin___stpncpy_chk) && USE_NATIVE_CHK
190 return __builtin___stpncpy_chk(__d, __s, __n, __fh_bos(__d, 0)); 190 return __builtin___stpncpy_chk(__d, __s, __n, __fh_bos(__d, 0));
191#else 191#else
192#if 0
193 // They check overlap across the whole range of the given length, but
194 // the given length is not what will actually be copied, rather it's
195 // the maximum length (if src is shorter, only length of src will be
196 // copied). This triggers false positives and traps where it shouldn't
197 // (e.g. in ICU tests).
192 if (__fh_overlap(__d, __s, __n)) 198 if (__fh_overlap(__d, __s, __n))
193 __builtin_trap(); 199 __builtin_trap();
200#endif
194 201
195 __fh_size_t __b = __fh_bos(__d, 0); 202 __fh_size_t __b = __fh_bos(__d, 0);
196 if (__n > __b && strlen(__s) + 1 > __b) 203 if (__n > __b && strlen(__s) + 1 > __b)
@@ -290,8 +297,15 @@ _FORTIFY_FN(strncpy) char *strncpy(char * _FORTIFY_POS0 __d,
290#if __has_builtin(__builtin___strncpy_chk) && USE_NATIVE_CHK 297#if __has_builtin(__builtin___strncpy_chk) && USE_NATIVE_CHK
291 return __builtin___strncpy_chk(__d, __s, __n, __fh_bos(__d, 0)); 298 return __builtin___strncpy_chk(__d, __s, __n, __fh_bos(__d, 0));
292#else 299#else
300#if 0
301 // They check overlap across the whole range of the given length, but
302 // the given length is not what will actually be copied, rather it's
303 // the maximum length (if src is shorter, only length of src will be
304 // copied). This triggers false positives and traps where it shouldn't
305 // (e.g. in ICU tests).
293 if (__fh_overlap(__d, __s, __n)) 306 if (__fh_overlap(__d, __s, __n))
294 __builtin_trap(); 307 __builtin_trap();
308#endif
295 309
296 __fh_size_t __b = __fh_bos(__d, 0); 310 __fh_size_t __b = __fh_bos(__d, 0);
297 if (__n > __b) 311 if (__n > __b)