diff options
| -rw-r--r-- | include/string.h | 15 | ||||
| -rw-r--r-- | tests/Makefile | 6 | ||||
| -rw-r--r-- | tests/test_memchr_null.c | 13 | ||||
| -rw-r--r-- | tests/test_memcpy_null_dst.c | 16 | ||||
| -rw-r--r-- | tests/test_memcpy_null_src.c | 16 | ||||
| -rw-r--r-- | tests/test_memmove_null_dst.c | 16 | ||||
| -rw-r--r-- | tests/test_memmove_null_src.c | 16 | ||||
| -rw-r--r-- | tests/test_memset_null.c | 13 |
8 files changed, 111 insertions, 0 deletions
diff --git a/include/string.h b/include/string.h index 75dadab..24c1501 100644 --- a/include/string.h +++ b/include/string.h | |||
| @@ -51,6 +51,9 @@ __error_if((__fh_bos(__od, 0) < __n), "'memcpy' called with `n` bigger than the | |||
| 51 | #if __has_builtin(__builtin___memcpy_chk) && USE_NATIVE_CHK | 51 | #if __has_builtin(__builtin___memcpy_chk) && USE_NATIVE_CHK |
| 52 | return __builtin___memcpy_chk(__od, __os, __n, __fh_bos(__od, 0)); | 52 | return __builtin___memcpy_chk(__od, __os, __n, __fh_bos(__od, 0)); |
| 53 | #else | 53 | #else |
| 54 | if (!__od || !__os) | ||
| 55 | __builtin_trap(); | ||
| 56 | |||
| 54 | __fh_size_t __bd = __fh_bos(__od, 0); | 57 | __fh_size_t __bd = __fh_bos(__od, 0); |
| 55 | __fh_size_t __bs = __fh_bos(__os, 0); | 58 | __fh_size_t __bs = __fh_bos(__os, 0); |
| 56 | char *__d = (char *)__od; | 59 | char *__d = (char *)__od; |
| @@ -75,6 +78,9 @@ _FORTIFY_FN(memmove) void *memmove(void * _FORTIFY_POS0 __d, | |||
| 75 | #if __has_builtin(__builtin___memmove_chk) && USE_NATIVE_CHK | 78 | #if __has_builtin(__builtin___memmove_chk) && USE_NATIVE_CHK |
| 76 | return __builtin___memmove_chk(__d, __s, __n, __fh_bos(__d, 0)); | 79 | return __builtin___memmove_chk(__d, __s, __n, __fh_bos(__d, 0)); |
| 77 | #else | 80 | #else |
| 81 | if (!__d || !__s) | ||
| 82 | __builtin_trap(); | ||
| 83 | |||
| 78 | __fh_size_t __bd = __fh_bos(__d, 0); | 84 | __fh_size_t __bd = __fh_bos(__d, 0); |
| 79 | __fh_size_t __bs = __fh_bos(__s, 0); | 85 | __fh_size_t __bs = __fh_bos(__s, 0); |
| 80 | 86 | ||
| @@ -94,6 +100,9 @@ __warning_if(__c != 0 && __n == 0, "'memset' will set `0` bytes; did you invert | |||
| 94 | #if __has_builtin(__builtin___memset_chk) && USE_NATIVE_CHK | 100 | #if __has_builtin(__builtin___memset_chk) && USE_NATIVE_CHK |
| 95 | return __builtin___memset_chk(__d, __c, __n, __fh_bos(__d, 0)); | 101 | return __builtin___memset_chk(__d, __c, __n, __fh_bos(__d, 0)); |
| 96 | #else | 102 | #else |
| 103 | if (!__d) | ||
| 104 | __builtin_trap(); | ||
| 105 | |||
| 97 | __fh_size_t __b = __fh_bos(__d, 0); | 106 | __fh_size_t __b = __fh_bos(__d, 0); |
| 98 | 107 | ||
| 99 | if (__n > __b) | 108 | if (__n > __b) |
| @@ -111,6 +120,9 @@ _FORTIFY_FN(memchr) void *memchr(const void * _FORTIFY_POS0 __d, int __c, size_t | |||
| 111 | #if __has_builtin(__builtin___memchr_chk) && USE_NATIVE_CHK | 120 | #if __has_builtin(__builtin___memchr_chk) && USE_NATIVE_CHK |
| 112 | return __builtin___memchr_chk(__d, __c, __n, __fh_bos(__d, 0)); | 121 | return __builtin___memchr_chk(__d, __c, __n, __fh_bos(__d, 0)); |
| 113 | #else | 122 | #else |
| 123 | if (!__d) | ||
| 124 | __builtin_trap(); | ||
| 125 | |||
| 114 | __fh_size_t __b = __fh_bos(__d, 0); | 126 | __fh_size_t __b = __fh_bos(__d, 0); |
| 115 | 127 | ||
| 116 | if (__n > __b) | 128 | if (__n > __b) |
| @@ -322,6 +334,9 @@ _FORTIFY_FN(mempcpy) void *mempcpy(void * _FORTIFY_POS0 __d, | |||
| 322 | #if __has_builtin(__builtin___mempcpy_chk) && USE_NATIVE_CHK | 334 | #if __has_builtin(__builtin___mempcpy_chk) && USE_NATIVE_CHK |
| 323 | return __builtin___mempcpy_chk(__d, __s, __n, __fh_bos(__d, 0)); | 335 | return __builtin___mempcpy_chk(__d, __s, __n, __fh_bos(__d, 0)); |
| 324 | #else | 336 | #else |
| 337 | if (!__d || !__s) | ||
| 338 | __builtin_trap(); | ||
| 339 | |||
| 325 | __fh_size_t __bd = __fh_bos(__d, 0); | 340 | __fh_size_t __bd = __fh_bos(__d, 0); |
| 326 | __fh_size_t __bs = __fh_bos(__s, 0); | 341 | __fh_size_t __bs = __fh_bos(__s, 0); |
| 327 | 342 | ||
diff --git a/tests/Makefile b/tests/Makefile index 352e6f8..b1223ea 100644 --- a/tests/Makefile +++ b/tests/Makefile | |||
| @@ -48,10 +48,15 @@ RUNTIME_TARGETS= \ | |||
| 48 | test_mbstowcs_static \ | 48 | test_mbstowcs_static \ |
| 49 | test_memchr_dynamic_read \ | 49 | test_memchr_dynamic_read \ |
| 50 | test_memchr_static_read \ | 50 | test_memchr_static_read \ |
| 51 | test_memchr_null \ | ||
| 51 | test_memcpy_dynamic_read \ | 52 | test_memcpy_dynamic_read \ |
| 52 | test_memcpy_dynamic_write \ | 53 | test_memcpy_dynamic_write \ |
| 53 | test_memcpy_overwrite_over \ | 54 | test_memcpy_overwrite_over \ |
| 54 | test_memcpy_static_read \ | 55 | test_memcpy_static_read \ |
| 56 | test_memcpy_null_src \ | ||
| 57 | test_memcpy_null_dst \ | ||
| 58 | test_memmove_null_src \ | ||
| 59 | test_memmove_null_dst \ | ||
| 55 | test_memmove_dynamic_read \ | 60 | test_memmove_dynamic_read \ |
| 56 | test_memmove_dynamic_write \ | 61 | test_memmove_dynamic_write \ |
| 57 | test_memmove_static_read \ | 62 | test_memmove_static_read \ |
| @@ -62,6 +67,7 @@ RUNTIME_TARGETS= \ | |||
| 62 | test_mempcpy_static_write \ | 67 | test_mempcpy_static_write \ |
| 63 | test_memset_dynamic_write \ | 68 | test_memset_dynamic_write \ |
| 64 | test_memset_static_write \ | 69 | test_memset_static_write \ |
| 70 | test_memset_null \ | ||
| 65 | test_poll_dynamic \ | 71 | test_poll_dynamic \ |
| 66 | test_poll_static \ | 72 | test_poll_static \ |
| 67 | test_ppoll_dynamic \ | 73 | test_ppoll_dynamic \ |
diff --git a/tests/test_memchr_null.c b/tests/test_memchr_null.c new file mode 100644 index 0000000..02b994d --- /dev/null +++ b/tests/test_memchr_null.c | |||
| @@ -0,0 +1,13 @@ | |||
| 1 | #include "common.h" | ||
| 2 | |||
| 3 | #include <string.h> | ||
| 4 | |||
| 5 | int main(int argc, char** argv) { | ||
| 6 | #ifndef __GNUC__ | ||
| 7 | CHK_FAIL_START | ||
| 8 | memchr(NULL, (int)'A', 0); | ||
| 9 | CHK_FAIL_END | ||
| 10 | #endif | ||
| 11 | |||
| 12 | return ret; | ||
| 13 | } | ||
diff --git a/tests/test_memcpy_null_dst.c b/tests/test_memcpy_null_dst.c new file mode 100644 index 0000000..9def69c --- /dev/null +++ b/tests/test_memcpy_null_dst.c | |||
| @@ -0,0 +1,16 @@ | |||
| 1 | #include "common.h" | ||
| 2 | |||
| 3 | #include <string.h> | ||
| 4 | |||
| 5 | int main(int argc, char** argv) { | ||
| 6 | #ifndef __GNUC__ | ||
| 7 | char buffer[12] = {0}; | ||
| 8 | |||
| 9 | CHK_FAIL_START | ||
| 10 | memcpy(buffer, NULL, 0); | ||
| 11 | CHK_FAIL_END | ||
| 12 | |||
| 13 | puts(buffer); | ||
| 14 | #endif | ||
| 15 | return ret; | ||
| 16 | } | ||
diff --git a/tests/test_memcpy_null_src.c b/tests/test_memcpy_null_src.c new file mode 100644 index 0000000..42f99a9 --- /dev/null +++ b/tests/test_memcpy_null_src.c | |||
| @@ -0,0 +1,16 @@ | |||
| 1 | #include "common.h" | ||
| 2 | |||
| 3 | #include <string.h> | ||
| 4 | |||
| 5 | int main(int argc, char** argv) { | ||
| 6 | #ifndef __GNUC__ | ||
| 7 | char buffer[12] = {0}; | ||
| 8 | |||
| 9 | CHK_FAIL_START | ||
| 10 | memcpy(NULL, buffer, 0); | ||
| 11 | CHK_FAIL_END | ||
| 12 | |||
| 13 | puts(buffer); | ||
| 14 | #endif | ||
| 15 | return ret; | ||
| 16 | } | ||
diff --git a/tests/test_memmove_null_dst.c b/tests/test_memmove_null_dst.c new file mode 100644 index 0000000..9455a5a --- /dev/null +++ b/tests/test_memmove_null_dst.c | |||
| @@ -0,0 +1,16 @@ | |||
| 1 | #include "common.h" | ||
| 2 | |||
| 3 | #include <string.h> | ||
| 4 | |||
| 5 | int main(int argc, char** argv) { | ||
| 6 | #ifndef __GNUC__ | ||
| 7 | char buffer[12] = {0}; | ||
| 8 | |||
| 9 | CHK_FAIL_START | ||
| 10 | memmove(buffer, NULL, 0); | ||
| 11 | CHK_FAIL_END | ||
| 12 | |||
| 13 | puts(buffer); | ||
| 14 | #endif | ||
| 15 | return ret; | ||
| 16 | } | ||
diff --git a/tests/test_memmove_null_src.c b/tests/test_memmove_null_src.c new file mode 100644 index 0000000..e03b97a --- /dev/null +++ b/tests/test_memmove_null_src.c | |||
| @@ -0,0 +1,16 @@ | |||
| 1 | #include "common.h" | ||
| 2 | |||
| 3 | #include <string.h> | ||
| 4 | |||
| 5 | int main(int argc, char** argv) { | ||
| 6 | #ifndef __GNUC__ | ||
| 7 | char buffer[12] = {0}; | ||
| 8 | |||
| 9 | CHK_FAIL_START | ||
| 10 | memmove(NULL, buffer, 0); | ||
| 11 | CHK_FAIL_END | ||
| 12 | |||
| 13 | puts(buffer); | ||
| 14 | #endif | ||
| 15 | return ret; | ||
| 16 | } | ||
diff --git a/tests/test_memset_null.c b/tests/test_memset_null.c new file mode 100644 index 0000000..0a2398b --- /dev/null +++ b/tests/test_memset_null.c | |||
| @@ -0,0 +1,13 @@ | |||
| 1 | #include "common.h" | ||
| 2 | |||
| 3 | #include <string.h> | ||
| 4 | |||
| 5 | int main(int argc, char** argv) { | ||
| 6 | #ifndef __GNUC__ | ||
| 7 | CHK_FAIL_START | ||
| 8 | memset(NULL, 0, 0); | ||
| 9 | CHK_FAIL_END | ||
| 10 | #endif | ||
| 11 | |||
| 12 | return ret; | ||
| 13 | } | ||
