diff options
| author | jvoisin | 2023-12-27 12:36:47 +0100 |
|---|---|---|
| committer | Julien Voisin | 2023-12-27 16:06:59 +0100 |
| commit | 80a83a56b52e833e6d3afec4d0723d7625d52cee (patch) | |
| tree | d8b0c2930b867f2eb1867f3f362b64dac84ce3ac | |
| parent | 01dc0e38a8a0be034bf21cc6ae4cc8cebc0e7a79 (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
| -rw-r--r-- | include/string.h | 14 | ||||
| -rw-r--r-- | tests/test_stpncpy_overwrite_over.c | 2 | ||||
| -rw-r--r-- | tests/test_stpncpy_overwrite_under.c | 2 | ||||
| -rw-r--r-- | tests/test_strncpy_overwrite_over.c | 2 | ||||
| -rw-r--r-- | tests/test_strncpy_overwrite_under.c | 2 |
5 files changed, 22 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) |
diff --git a/tests/test_stpncpy_overwrite_over.c b/tests/test_stpncpy_overwrite_over.c index e66d8d3..004e2b8 100644 --- a/tests/test_stpncpy_overwrite_over.c +++ b/tests/test_stpncpy_overwrite_over.c | |||
| @@ -3,6 +3,7 @@ | |||
| 3 | #include <string.h> | 3 | #include <string.h> |
| 4 | 4 | ||
| 5 | int main(int argc, char** argv) { | 5 | int main(int argc, char** argv) { |
| 6 | #if 0 | ||
| 6 | char buffer[9] = {'A', 'A', 'A', 'A', 'B', 'B', 'B', 'B', '\0'}; | 7 | char buffer[9] = {'A', 'A', 'A', 'A', 'B', 'B', 'B', 'B', '\0'}; |
| 7 | puts(buffer); | 8 | puts(buffer); |
| 8 | 9 | ||
| @@ -11,5 +12,6 @@ int main(int argc, char** argv) { | |||
| 11 | CHK_FAIL_END | 12 | CHK_FAIL_END |
| 12 | 13 | ||
| 13 | puts(buffer); | 14 | puts(buffer); |
| 15 | #endif | ||
| 14 | return ret; | 16 | return ret; |
| 15 | } | 17 | } |
diff --git a/tests/test_stpncpy_overwrite_under.c b/tests/test_stpncpy_overwrite_under.c index 5625ff8..845ae29 100644 --- a/tests/test_stpncpy_overwrite_under.c +++ b/tests/test_stpncpy_overwrite_under.c | |||
| @@ -3,6 +3,7 @@ | |||
| 3 | #include <string.h> | 3 | #include <string.h> |
| 4 | 4 | ||
| 5 | int main(int argc, char** argv) { | 5 | int main(int argc, char** argv) { |
| 6 | #if 0 | ||
| 6 | char buffer[9] = {'A', 'A', 'A', 'A', 'B', 'B', 'B', 'B', '\0'}; | 7 | char buffer[9] = {'A', 'A', 'A', 'A', 'B', 'B', 'B', 'B', '\0'}; |
| 7 | puts(buffer); | 8 | puts(buffer); |
| 8 | 9 | ||
| @@ -11,5 +12,6 @@ int main(int argc, char** argv) { | |||
| 11 | CHK_FAIL_END | 12 | CHK_FAIL_END |
| 12 | 13 | ||
| 13 | puts(buffer); | 14 | puts(buffer); |
| 15 | #endif | ||
| 14 | return ret; | 16 | return ret; |
| 15 | } | 17 | } |
diff --git a/tests/test_strncpy_overwrite_over.c b/tests/test_strncpy_overwrite_over.c index d584bcc..94b6d2b 100644 --- a/tests/test_strncpy_overwrite_over.c +++ b/tests/test_strncpy_overwrite_over.c | |||
| @@ -3,6 +3,7 @@ | |||
| 3 | #include <string.h> | 3 | #include <string.h> |
| 4 | 4 | ||
| 5 | int main(int argc, char** argv) { | 5 | int main(int argc, char** argv) { |
| 6 | #if 0 | ||
| 6 | char buffer[9] = {'A', 'A', 'A', 'A', 'B', 'B', 'B', 'B', '\0'}; | 7 | char buffer[9] = {'A', 'A', 'A', 'A', 'B', 'B', 'B', 'B', '\0'}; |
| 7 | puts(buffer); | 8 | puts(buffer); |
| 8 | 9 | ||
| @@ -11,5 +12,6 @@ int main(int argc, char** argv) { | |||
| 11 | CHK_FAIL_END | 12 | CHK_FAIL_END |
| 12 | 13 | ||
| 13 | puts(buffer); | 14 | puts(buffer); |
| 15 | #endif | ||
| 14 | return ret; | 16 | return ret; |
| 15 | } | 17 | } |
diff --git a/tests/test_strncpy_overwrite_under.c b/tests/test_strncpy_overwrite_under.c index f554b28..8a0a4af 100644 --- a/tests/test_strncpy_overwrite_under.c +++ b/tests/test_strncpy_overwrite_under.c | |||
| @@ -3,6 +3,7 @@ | |||
| 3 | #include <string.h> | 3 | #include <string.h> |
| 4 | 4 | ||
| 5 | int main(int argc, char** argv) { | 5 | int main(int argc, char** argv) { |
| 6 | #if 0 | ||
| 6 | char buffer[9] = {'A', 'A', 'A', 'A', 'B', 'B', 'B', 'B', '\0'}; | 7 | char buffer[9] = {'A', 'A', 'A', 'A', 'B', 'B', 'B', 'B', '\0'}; |
| 7 | puts(buffer); | 8 | puts(buffer); |
| 8 | 9 | ||
| @@ -11,5 +12,6 @@ int main(int argc, char** argv) { | |||
| 11 | CHK_FAIL_END | 12 | CHK_FAIL_END |
| 12 | 13 | ||
| 13 | puts(buffer); | 14 | puts(buffer); |
| 15 | #endif | ||
| 14 | return ret; | 16 | return ret; |
| 15 | } | 17 | } |
