diff options
Diffstat (limited to '')
28 files changed, 422 insertions, 36 deletions
diff --git a/tests/Makefile b/tests/Makefile index 9bedd16..1334efd 100644 --- a/tests/Makefile +++ b/tests/Makefile | |||
| @@ -17,6 +17,7 @@ RUNTIME_TARGETS= \ | |||
| 17 | test_bzero_static_write \ | 17 | test_bzero_static_write \ |
| 18 | test_compile \ | 18 | test_compile \ |
| 19 | test_confstr_dynamic \ | 19 | test_confstr_dynamic \ |
| 20 | test_confstr_static \ | ||
| 20 | test_fgets_dynamic \ | 21 | test_fgets_dynamic \ |
| 21 | test_fgets_static \ | 22 | test_fgets_static \ |
| 22 | test_fgetws_dynamic \ | 23 | test_fgetws_dynamic \ |
| @@ -39,7 +40,9 @@ RUNTIME_TARGETS= \ | |||
| 39 | test_getlogin_r_static \ | 40 | test_getlogin_r_static \ |
| 40 | test_memcpy_dynamic_read \ | 41 | test_memcpy_dynamic_read \ |
| 41 | test_memcpy_dynamic_write \ | 42 | test_memcpy_dynamic_write \ |
| 43 | test_memcpy_overlap \ | ||
| 42 | test_memcpy_static_read \ | 44 | test_memcpy_static_read \ |
| 45 | test_memcpy_static_write \ | ||
| 43 | test_memmove_dynamic_read \ | 46 | test_memmove_dynamic_read \ |
| 44 | test_memmove_dynamic_write \ | 47 | test_memmove_dynamic_write \ |
| 45 | test_memmove_static_read \ | 48 | test_memmove_static_read \ |
| @@ -52,14 +55,22 @@ RUNTIME_TARGETS= \ | |||
| 52 | test_memset_static_write \ | 55 | test_memset_static_write \ |
| 53 | test_mbsnrtowcs_dynamic \ | 56 | test_mbsnrtowcs_dynamic \ |
| 54 | test_mbsnrtowcs_static \ | 57 | test_mbsnrtowcs_static \ |
| 58 | test_mbsrtowcs_dynamic \ | ||
| 59 | test_mbsrtowcs_static \ | ||
| 60 | test_mbstowcs_dynamic \ | ||
| 61 | test_mbstowcs_static \ | ||
| 55 | test_poll_dynamic \ | 62 | test_poll_dynamic \ |
| 56 | test_poll_static \ | 63 | test_poll_static \ |
| 57 | test_ppoll_dynamic \ | 64 | test_ppoll_dynamic \ |
| 58 | test_ppoll_static \ | 65 | test_ppoll_static \ |
| 66 | test_pread_dynamic \ | ||
| 67 | test_pread_static \ | ||
| 59 | test_read_dynamic \ | 68 | test_read_dynamic \ |
| 60 | test_read_static \ | 69 | test_read_static \ |
| 61 | test_readlink_dynamic \ | 70 | test_readlink_dynamic \ |
| 62 | test_readlink_static \ | 71 | test_readlink_static \ |
| 72 | test_readlinkat_dynamic \ | ||
| 73 | test_readlinkat_static \ | ||
| 63 | test_realpath_null \ | 74 | test_realpath_null \ |
| 64 | test_realpath \ | 75 | test_realpath \ |
| 65 | test_recv_dynamic \ | 76 | test_recv_dynamic \ |
| @@ -70,12 +81,15 @@ RUNTIME_TARGETS= \ | |||
| 70 | test_send_static \ | 81 | test_send_static \ |
| 71 | test_sendto_dynamic \ | 82 | test_sendto_dynamic \ |
| 72 | test_sendto_static \ | 83 | test_sendto_static \ |
| 84 | test_snprintf_dynamic \ | ||
| 85 | test_snprintf_static \ | ||
| 73 | test_sprintf \ | 86 | test_sprintf \ |
| 74 | test_sprintf_62 \ | 87 | test_sprintf_62 \ |
| 75 | test_stpcpy_dynamic_write \ | 88 | test_stpcpy_dynamic_write \ |
| 76 | test_stpcpy_static_write \ | 89 | test_stpcpy_static_write \ |
| 77 | test_stpncpy_dynamic_write \ | 90 | test_stpncpy_dynamic_write \ |
| 78 | test_stpncpy_static_write \ | 91 | test_stpncpy_static_write \ |
| 92 | test_strcat_dynamic_write \ | ||
| 79 | test_strcat_static_write \ | 93 | test_strcat_static_write \ |
| 80 | test_strcpy_dynamic_write \ | 94 | test_strcpy_dynamic_write \ |
| 81 | test_strcpy_static_write \ | 95 | test_strcpy_static_write \ |
| @@ -96,6 +110,7 @@ RUNTIME_TARGETS= \ | |||
| 96 | test_swab_dynamic_write \ | 110 | test_swab_dynamic_write \ |
| 97 | test_swab_negative \ | 111 | test_swab_negative \ |
| 98 | test_swab_static_read \ | 112 | test_swab_static_read \ |
| 113 | test_swab_static_write \ | ||
| 99 | test_ttyname_r_dynamic \ | 114 | test_ttyname_r_dynamic \ |
| 100 | test_ttyname_r_static \ | 115 | test_ttyname_r_static \ |
| 101 | test_vsnprintf_dynamic \ | 116 | test_vsnprintf_dynamic \ |
| @@ -104,15 +119,23 @@ RUNTIME_TARGETS= \ | |||
| 104 | test_wcrtomb \ | 119 | test_wcrtomb \ |
| 105 | test_wcsnrtombs_dynamic \ | 120 | test_wcsnrtombs_dynamic \ |
| 106 | test_wcsnrtombs_static \ | 121 | test_wcsnrtombs_static \ |
| 122 | test_wcscat_dynamic_write \ | ||
| 107 | test_wcscat_static_write \ | 123 | test_wcscat_static_write \ |
| 124 | test_wcscpy_dynamic_write \ | ||
| 108 | test_wcscpy_static_write \ | 125 | test_wcscpy_static_write \ |
| 126 | test_wcsncat_dynamic_write \ | ||
| 109 | test_wcsncat_n_eq_buf \ | 127 | test_wcsncat_n_eq_buf \ |
| 110 | test_wcsncat_n_gt_buf \ | 128 | test_wcsncat_n_gt_buf \ |
| 111 | test_wcsncat_n_lt_buf \ | 129 | test_wcsncat_n_lt_buf \ |
| 112 | test_wcsncat_n_one \ | 130 | test_wcsncat_n_one \ |
| 113 | test_wcsncat_safe \ | 131 | test_wcsncat_safe \ |
| 114 | test_wcsncat_static_write \ | 132 | test_wcsncat_static_write \ |
| 133 | test_wcsncpy_dynamic_write \ | ||
| 115 | test_wcsncpy_static_write \ | 134 | test_wcsncpy_static_write \ |
| 135 | test_wcsrtombs_dynamic \ | ||
| 136 | test_wcsrtombs_static \ | ||
| 137 | test_wcstombs_dynamic \ | ||
| 138 | test_wcstombs_static \ | ||
| 116 | test_wmemcpy_dynamic_read \ | 139 | test_wmemcpy_dynamic_read \ |
| 117 | test_wmemcpy_dynamic_write \ | 140 | test_wmemcpy_dynamic_write \ |
| 118 | test_wmemcpy_static_read \ | 141 | test_wmemcpy_static_read \ |
diff --git a/tests/test_confstr_static.c b/tests/test_confstr_static.c new file mode 100644 index 0000000..f468532 --- /dev/null +++ b/tests/test_confstr_static.c | |||
| @@ -0,0 +1,16 @@ | |||
| 1 | #include "common.h" | ||
| 2 | |||
| 3 | #include <unistd.h> | ||
| 4 | |||
| 5 | int main(int argc, char** argv) { | ||
| 6 | char buffer[4] = {0}; | ||
| 7 | |||
| 8 | confstr(_CS_PATH, buffer, 4); | ||
| 9 | |||
| 10 | CHK_FAIL_START | ||
| 11 | confstr(_CS_PATH, buffer, 8); | ||
| 12 | CHK_FAIL_END | ||
| 13 | |||
| 14 | puts(buffer); | ||
| 15 | return ret; | ||
| 16 | } | ||
diff --git a/tests/test_mbsnrtowcs_dynamic.c b/tests/test_mbsnrtowcs_dynamic.c index 58575d3..b94ced5 100644 --- a/tests/test_mbsnrtowcs_dynamic.c +++ b/tests/test_mbsnrtowcs_dynamic.c | |||
| @@ -15,9 +15,9 @@ int main(int argc, char** argv) { | |||
| 15 | mbsnrtowcs(buffer, &srcp, 2, 2, &st); | 15 | mbsnrtowcs(buffer, &srcp, 2, 2, &st); |
| 16 | 16 | ||
| 17 | /* Unsafe: ask to write argc (10) wide chars into 4-element buffer. */ | 17 | /* Unsafe: ask to write argc (10) wide chars into 4-element buffer. */ |
| 18 | CHK_FAIL_START | ||
| 19 | srcp = src; | 18 | srcp = src; |
| 20 | memset(&st, 0, sizeof(st)); | 19 | memset(&st, 0, sizeof(st)); |
| 20 | CHK_FAIL_START | ||
| 21 | mbsnrtowcs(buffer, &srcp, 10, argc, &st); | 21 | mbsnrtowcs(buffer, &srcp, 10, argc, &st); |
| 22 | CHK_FAIL_END | 22 | CHK_FAIL_END |
| 23 | 23 | ||
diff --git a/tests/test_mbsnrtowcs_static.c b/tests/test_mbsnrtowcs_static.c index 755d453..40fe00a 100644 --- a/tests/test_mbsnrtowcs_static.c +++ b/tests/test_mbsnrtowcs_static.c | |||
| @@ -15,9 +15,9 @@ int main(int argc, char** argv) { | |||
| 15 | mbsnrtowcs(buffer, &srcp, 4, 2, &st); | 15 | mbsnrtowcs(buffer, &srcp, 4, 2, &st); |
| 16 | 16 | ||
| 17 | /* Unsafe: ask to write 16 wide chars into 4-element buffer */ | 17 | /* Unsafe: ask to write 16 wide chars into 4-element buffer */ |
| 18 | CHK_FAIL_START | ||
| 19 | srcp = src; | 18 | srcp = src; |
| 20 | memset(&st, 0, sizeof(st)); | 19 | memset(&st, 0, sizeof(st)); |
| 20 | CHK_FAIL_START | ||
| 21 | mbsnrtowcs(buffer, &srcp, 16, 16, &st); | 21 | mbsnrtowcs(buffer, &srcp, 16, 16, &st); |
| 22 | CHK_FAIL_END | 22 | CHK_FAIL_END |
| 23 | 23 | ||
diff --git a/tests/test_mbsrtowcs_dynamic.c b/tests/test_mbsrtowcs_dynamic.c new file mode 100644 index 0000000..cbba0a3 --- /dev/null +++ b/tests/test_mbsrtowcs_dynamic.c | |||
| @@ -0,0 +1,24 @@ | |||
| 1 | #include "common.h" | ||
| 2 | |||
| 3 | #include <wchar.h> | ||
| 4 | #include <string.h> | ||
| 5 | |||
| 6 | int main(int argc, char** argv) { | ||
| 7 | wchar_t buffer[4] = {0}; | ||
| 8 | const char *src = "ABCDEFGHIJ"; | ||
| 9 | const char *srcp = src; | ||
| 10 | mbstate_t st; | ||
| 11 | memset(&st, 0, sizeof(st)); | ||
| 12 | |||
| 13 | srcp = src; | ||
| 14 | mbsrtowcs(buffer, &srcp, 2, &st); | ||
| 15 | |||
| 16 | srcp = src; | ||
| 17 | memset(&st, 0, sizeof(st)); | ||
| 18 | CHK_FAIL_START | ||
| 19 | mbsrtowcs(buffer, &srcp, argc + 15, &st); | ||
| 20 | CHK_FAIL_END | ||
| 21 | |||
| 22 | printf("%ls\n", buffer); | ||
| 23 | return ret; | ||
| 24 | } | ||
diff --git a/tests/test_mbsrtowcs_static.c b/tests/test_mbsrtowcs_static.c new file mode 100644 index 0000000..f90f29f --- /dev/null +++ b/tests/test_mbsrtowcs_static.c | |||
| @@ -0,0 +1,24 @@ | |||
| 1 | #include "common.h" | ||
| 2 | |||
| 3 | #include <wchar.h> | ||
| 4 | #include <string.h> | ||
| 5 | |||
| 6 | int main(int argc, char** argv) { | ||
| 7 | wchar_t buffer[4] = {0}; | ||
| 8 | const char *src = "ABCDEFGHIJ"; | ||
| 9 | const char *srcp = src; | ||
| 10 | mbstate_t st; | ||
| 11 | memset(&st, 0, sizeof(st)); | ||
| 12 | |||
| 13 | srcp = src; | ||
| 14 | mbsrtowcs(buffer, &srcp, 2, &st); | ||
| 15 | |||
| 16 | srcp = src; | ||
| 17 | memset(&st, 0, sizeof(st)); | ||
| 18 | CHK_FAIL_START | ||
| 19 | mbsrtowcs(buffer, &srcp, 16, &st); | ||
| 20 | CHK_FAIL_END | ||
| 21 | |||
| 22 | printf("%ls\n", buffer); | ||
| 23 | return ret; | ||
| 24 | } | ||
diff --git a/tests/test_mbstowcs_dynamic.c b/tests/test_mbstowcs_dynamic.c new file mode 100644 index 0000000..4295fbd --- /dev/null +++ b/tests/test_mbstowcs_dynamic.c | |||
| @@ -0,0 +1,16 @@ | |||
| 1 | #include "common.h" | ||
| 2 | |||
| 3 | #include <wchar.h> | ||
| 4 | |||
| 5 | int main(int argc, char** argv) { | ||
| 6 | wchar_t buffer[4] = {0}; | ||
| 7 | |||
| 8 | mbstowcs(buffer, "AB", 2); | ||
| 9 | |||
| 10 | CHK_FAIL_START | ||
| 11 | mbstowcs(buffer, "ABCDEFGHIJ", argc + 15); | ||
| 12 | CHK_FAIL_END | ||
| 13 | |||
| 14 | printf("%ls\n", buffer); | ||
| 15 | return ret; | ||
| 16 | } | ||
diff --git a/tests/test_mbstowcs_static.c b/tests/test_mbstowcs_static.c new file mode 100644 index 0000000..585c4f0 --- /dev/null +++ b/tests/test_mbstowcs_static.c | |||
| @@ -0,0 +1,16 @@ | |||
| 1 | #include "common.h" | ||
| 2 | |||
| 3 | #include <wchar.h> | ||
| 4 | |||
| 5 | int main(int argc, char** argv) { | ||
| 6 | wchar_t buffer[4] = {0}; | ||
| 7 | |||
| 8 | mbstowcs(buffer, "AB", 2); | ||
| 9 | |||
| 10 | CHK_FAIL_START | ||
| 11 | mbstowcs(buffer, "ABCDEFGHIJ", 16); | ||
| 12 | CHK_FAIL_END | ||
| 13 | |||
| 14 | printf("%ls\n", buffer); | ||
| 15 | return ret; | ||
| 16 | } | ||
diff --git a/tests/test_memcpy_overlap.c b/tests/test_memcpy_overlap.c new file mode 100644 index 0000000..f8c6639 --- /dev/null +++ b/tests/test_memcpy_overlap.c | |||
| @@ -0,0 +1,27 @@ | |||
| 1 | #include "common.h" | ||
| 2 | |||
| 3 | #include <string.h> | ||
| 4 | |||
| 5 | /* fortify-headers' memcpy traps when src/dst overlap (but not when src == dst). | ||
| 6 | * This test exercises that overlap-detection branch, which is unique to this | ||
| 7 | * implementation. The pointer offset is hidden behind a volatile so -Wrestrict | ||
| 8 | * cannot see the overlap at compile time. */ | ||
| 9 | |||
| 10 | int main(int argc, char** argv) { | ||
| 11 | static char buffer[16] = "0123456789ABCDE"; | ||
| 12 | volatile int off = 2; /* hidden from the compiler so -Wrestrict won't see */ | ||
| 13 | char *p = buffer; | ||
| 14 | char *q = p + off; | ||
| 15 | |||
| 16 | /* dst == src: must NOT trap */ | ||
| 17 | memcpy(p, p, 8); | ||
| 18 | puts(buffer); | ||
| 19 | |||
| 20 | /* Overlapping src/dst (dst < src): must trap */ | ||
| 21 | CHK_FAIL_START | ||
| 22 | memcpy(p, q, 8); | ||
| 23 | CHK_FAIL_END | ||
| 24 | |||
| 25 | puts(buffer); | ||
| 26 | return ret; | ||
| 27 | } | ||
diff --git a/tests/test_pread_dynamic.c b/tests/test_pread_dynamic.c new file mode 100644 index 0000000..a04c661 --- /dev/null +++ b/tests/test_pread_dynamic.c | |||
| @@ -0,0 +1,16 @@ | |||
| 1 | #include "common.h" | ||
| 2 | |||
| 3 | #include <unistd.h> | ||
| 4 | |||
| 5 | int main(int argc, char** argv) { | ||
| 6 | char buffer[8] = {0}; | ||
| 7 | |||
| 8 | pread(0, buffer, 6, 0); | ||
| 9 | |||
| 10 | CHK_FAIL_START | ||
| 11 | pread(0, buffer, argc, 0); | ||
| 12 | CHK_FAIL_END | ||
| 13 | |||
| 14 | puts(buffer); | ||
| 15 | return ret; | ||
| 16 | } | ||
diff --git a/tests/test_pread_static.c b/tests/test_pread_static.c new file mode 100644 index 0000000..919fff7 --- /dev/null +++ b/tests/test_pread_static.c | |||
| @@ -0,0 +1,16 @@ | |||
| 1 | #include "common.h" | ||
| 2 | |||
| 3 | #include <unistd.h> | ||
| 4 | |||
| 5 | int main(int argc, char** argv) { | ||
| 6 | char buffer[12] = {0}; | ||
| 7 | |||
| 8 | pread(0, buffer, 10, 0); | ||
| 9 | |||
| 10 | CHK_FAIL_START | ||
| 11 | pread(0, buffer, 14, 0); | ||
| 12 | CHK_FAIL_END | ||
| 13 | |||
| 14 | puts(buffer); | ||
| 15 | return ret; | ||
| 16 | } | ||
diff --git a/tests/test_readlinkat_dynamic.c b/tests/test_readlinkat_dynamic.c new file mode 100644 index 0000000..6976b74 --- /dev/null +++ b/tests/test_readlinkat_dynamic.c | |||
| @@ -0,0 +1,17 @@ | |||
| 1 | #include "common.h" | ||
| 2 | |||
| 3 | #include <fcntl.h> | ||
| 4 | #include <unistd.h> | ||
| 5 | |||
| 6 | int main(int argc, char** argv) { | ||
| 7 | char buffer[8] = {0}; | ||
| 8 | |||
| 9 | readlinkat(AT_FDCWD, "", buffer, 6); | ||
| 10 | |||
| 11 | CHK_FAIL_START | ||
| 12 | readlinkat(AT_FDCWD, "", buffer, argc); | ||
| 13 | CHK_FAIL_END | ||
| 14 | |||
| 15 | puts(buffer); | ||
| 16 | return ret; | ||
| 17 | } | ||
diff --git a/tests/test_readlinkat_static.c b/tests/test_readlinkat_static.c new file mode 100644 index 0000000..3331b1e --- /dev/null +++ b/tests/test_readlinkat_static.c | |||
| @@ -0,0 +1,17 @@ | |||
| 1 | #include "common.h" | ||
| 2 | |||
| 3 | #include <fcntl.h> | ||
| 4 | #include <unistd.h> | ||
| 5 | |||
| 6 | int main(int argc, char** argv) { | ||
| 7 | char buffer[12] = {0}; | ||
| 8 | |||
| 9 | readlinkat(AT_FDCWD, "", buffer, 10); | ||
| 10 | |||
| 11 | CHK_FAIL_START | ||
| 12 | readlinkat(AT_FDCWD, "", buffer, 14); | ||
| 13 | CHK_FAIL_END | ||
| 14 | |||
| 15 | puts(buffer); | ||
| 16 | return ret; | ||
| 17 | } | ||
diff --git a/tests/test_select_dynamic.c b/tests/test_select_dynamic.c deleted file mode 100644 index e67baf3..0000000 --- a/tests/test_select_dynamic.c +++ /dev/null | |||
| @@ -1,16 +0,0 @@ | |||
| 1 | #include "common.h" | ||
| 2 | |||
| 3 | #include <sys/select.h> | ||
| 4 | |||
| 5 | int main(int argc, char** argv) { | ||
| 6 | #if !defined(__clang__) | ||
| 7 | fd_set rfds; | ||
| 8 | |||
| 9 | CHK_FAIL_START | ||
| 10 | select(FD_SETSIZE + argc, &rfds, NULL, NULL, NULL); | ||
| 11 | CHK_FAIL_END | ||
| 12 | |||
| 13 | puts((const char*)&rfds); | ||
| 14 | #endif | ||
| 15 | return ret; | ||
| 16 | } | ||
diff --git a/tests/test_select_static.c b/tests/test_select_static.c deleted file mode 100644 index c2abf7f..0000000 --- a/tests/test_select_static.c +++ /dev/null | |||
| @@ -1,16 +0,0 @@ | |||
| 1 | #include "common.h" | ||
| 2 | |||
| 3 | #include <sys/select.h> | ||
| 4 | |||
| 5 | int main(int argc, char** argv) { | ||
| 6 | #if !defined(__clang__) | ||
| 7 | fd_set rfds; | ||
| 8 | |||
| 9 | CHK_FAIL_START | ||
| 10 | select(1337, &rfds, NULL, NULL, NULL); | ||
| 11 | CHK_FAIL_END | ||
| 12 | |||
| 13 | puts((const char*)&rfds); | ||
| 14 | #endif | ||
| 15 | return ret; | ||
| 16 | } | ||
diff --git a/tests/test_snprintf_dynamic.c b/tests/test_snprintf_dynamic.c new file mode 100644 index 0000000..e5f8fcc --- /dev/null +++ b/tests/test_snprintf_dynamic.c | |||
| @@ -0,0 +1,18 @@ | |||
| 1 | #include "common.h" | ||
| 2 | |||
| 3 | #include <stdio.h> | ||
| 4 | |||
| 5 | int main(int argc, char** argv) { | ||
| 6 | #if !defined(__clang__) | ||
| 7 | char buffer[8] = {0}; | ||
| 8 | snprintf(buffer, sizeof(buffer), "%s", "1234567"); | ||
| 9 | puts(buffer); | ||
| 10 | |||
| 11 | CHK_FAIL_START | ||
| 12 | snprintf(buffer, sizeof(buffer) + argc + 3, "%s", "1234567890"); | ||
| 13 | CHK_FAIL_END | ||
| 14 | |||
| 15 | puts(buffer); | ||
| 16 | #endif | ||
| 17 | return ret; | ||
| 18 | } | ||
diff --git a/tests/test_snprintf_static.c b/tests/test_snprintf_static.c new file mode 100644 index 0000000..d3df447 --- /dev/null +++ b/tests/test_snprintf_static.c | |||
| @@ -0,0 +1,18 @@ | |||
| 1 | #include "common.h" | ||
| 2 | |||
| 3 | #include <stdio.h> | ||
| 4 | |||
| 5 | int main(int argc, char** argv) { | ||
| 6 | #if !defined(__clang__) | ||
| 7 | char buffer[8] = {0}; | ||
| 8 | snprintf(buffer, sizeof(buffer), "%s", "1234567"); | ||
| 9 | puts(buffer); | ||
| 10 | |||
| 11 | CHK_FAIL_START | ||
| 12 | snprintf(buffer, sizeof(buffer) + 4, "%s", "1234567890"); | ||
| 13 | CHK_FAIL_END | ||
| 14 | |||
| 15 | puts(buffer); | ||
| 16 | #endif | ||
| 17 | return ret; | ||
| 18 | } | ||
diff --git a/tests/test_strcat_dynamic_write.c b/tests/test_strcat_dynamic_write.c new file mode 100644 index 0000000..dde9e44 --- /dev/null +++ b/tests/test_strcat_dynamic_write.c | |||
| @@ -0,0 +1,15 @@ | |||
| 1 | #include "common.h" | ||
| 2 | |||
| 3 | #include <string.h> | ||
| 4 | |||
| 5 | int main(int argc, char** argv) { | ||
| 6 | char buffer[8] = {0}; | ||
| 7 | strcat(buffer, "12345"); | ||
| 8 | |||
| 9 | CHK_FAIL_START | ||
| 10 | strcat(buffer, argv[1]); | ||
| 11 | CHK_FAIL_END | ||
| 12 | |||
| 13 | puts(buffer); | ||
| 14 | return ret; | ||
| 15 | } | ||
diff --git a/tests/test_wcscat_dynamic_write.c b/tests/test_wcscat_dynamic_write.c new file mode 100644 index 0000000..064f018 --- /dev/null +++ b/tests/test_wcscat_dynamic_write.c | |||
| @@ -0,0 +1,21 @@ | |||
| 1 | #include "common.h" | ||
| 2 | |||
| 3 | #include <wchar.h> | ||
| 4 | |||
| 5 | int main(int argc, char** argv) { | ||
| 6 | wchar_t buffer[8] = {0}; | ||
| 7 | wchar_t src[20]; | ||
| 8 | int i; | ||
| 9 | wcscat(buffer, L"α"); | ||
| 10 | |||
| 11 | for (i = 0; i < argc; i++) | ||
| 12 | src[i] = L'A'; | ||
| 13 | src[i] = L'\0'; | ||
| 14 | |||
| 15 | CHK_FAIL_START | ||
| 16 | wcscat(buffer, src); | ||
| 17 | CHK_FAIL_END | ||
| 18 | |||
| 19 | printf("%ls\n", buffer); | ||
| 20 | return ret; | ||
| 21 | } | ||
diff --git a/tests/test_wcscpy_dynamic_write.c b/tests/test_wcscpy_dynamic_write.c new file mode 100644 index 0000000..5055e9c --- /dev/null +++ b/tests/test_wcscpy_dynamic_write.c | |||
| @@ -0,0 +1,22 @@ | |||
| 1 | #include "common.h" | ||
| 2 | |||
| 3 | #include <wchar.h> | ||
| 4 | |||
| 5 | int main(int argc, char** argv) { | ||
| 6 | wchar_t buffer[8] = {0}; | ||
| 7 | wchar_t src[20]; | ||
| 8 | int i; | ||
| 9 | wcscpy(buffer, L"α"); | ||
| 10 | printf("%ls\n", buffer); | ||
| 11 | |||
| 12 | for (i = 0; i < argc; i++) | ||
| 13 | src[i] = L'A'; | ||
| 14 | src[i] = L'\0'; | ||
| 15 | |||
| 16 | CHK_FAIL_START | ||
| 17 | wcscpy(buffer, src); | ||
| 18 | CHK_FAIL_END | ||
| 19 | |||
| 20 | printf("%ls\n", buffer); | ||
| 21 | return ret; | ||
| 22 | } | ||
diff --git a/tests/test_wcsncat_dynamic_write.c b/tests/test_wcsncat_dynamic_write.c new file mode 100644 index 0000000..9f87172 --- /dev/null +++ b/tests/test_wcsncat_dynamic_write.c | |||
| @@ -0,0 +1,16 @@ | |||
| 1 | #include "common.h" | ||
| 2 | |||
| 3 | #include <wchar.h> | ||
| 4 | |||
| 5 | int main(int argc, char** argv) { | ||
| 6 | wchar_t buffer[8] = {0}; | ||
| 7 | wcsncat(buffer, L"αβγδεζηθικλμνξοπρστυφχψω", 2); | ||
| 8 | printf("%ls\n", buffer); | ||
| 9 | |||
| 10 | CHK_FAIL_START | ||
| 11 | wcsncat(buffer, L"αβγδεζηθικλμνξοπρστυφχψω", argc + 1336); | ||
| 12 | CHK_FAIL_END | ||
| 13 | |||
| 14 | printf("%ls\n", buffer); | ||
| 15 | return ret; | ||
| 16 | } | ||
diff --git a/tests/test_wcsncpy_dynamic_write.c b/tests/test_wcsncpy_dynamic_write.c new file mode 100644 index 0000000..3078c0e --- /dev/null +++ b/tests/test_wcsncpy_dynamic_write.c | |||
| @@ -0,0 +1,16 @@ | |||
| 1 | #include "common.h" | ||
| 2 | |||
| 3 | #include <wchar.h> | ||
| 4 | |||
| 5 | int main(int argc, char** argv) { | ||
| 6 | wchar_t buffer[8] = {0}; | ||
| 7 | wcsncpy(buffer, L"αβγδεζηθικλμνξοπρστυφχψω", 1); | ||
| 8 | printf("%ls\n", buffer); | ||
| 9 | |||
| 10 | CHK_FAIL_START | ||
| 11 | wcsncpy(buffer, L"αβγδεζηθικλμνξοπρστυφχψω", argc + 1336); | ||
| 12 | CHK_FAIL_END | ||
| 13 | |||
| 14 | printf("%ls\n", buffer); | ||
| 15 | return ret; | ||
| 16 | } | ||
diff --git a/tests/test_wcsnrtombs_dynamic.c b/tests/test_wcsnrtombs_dynamic.c index 28b03bf..1637e71 100644 --- a/tests/test_wcsnrtombs_dynamic.c +++ b/tests/test_wcsnrtombs_dynamic.c | |||
| @@ -15,9 +15,9 @@ int main(int argc, char** argv) { | |||
| 15 | wcsnrtombs(buffer, &srcp, 4, 4, &st); | 15 | wcsnrtombs(buffer, &srcp, 4, 4, &st); |
| 16 | 16 | ||
| 17 | /* Unsafe: ask to write argc (10) bytes into 8-byte buffer. */ | 17 | /* Unsafe: ask to write argc (10) bytes into 8-byte buffer. */ |
| 18 | CHK_FAIL_START | ||
| 19 | srcp = src; | 18 | srcp = src; |
| 20 | memset(&st, 0, sizeof(st)); | 19 | memset(&st, 0, sizeof(st)); |
| 20 | CHK_FAIL_START | ||
| 21 | wcsnrtombs(buffer, &srcp, 4, argc, &st); | 21 | wcsnrtombs(buffer, &srcp, 4, argc, &st); |
| 22 | CHK_FAIL_END | 22 | CHK_FAIL_END |
| 23 | 23 | ||
diff --git a/tests/test_wcsnrtombs_static.c b/tests/test_wcsnrtombs_static.c index 7f2883f..da529f1 100644 --- a/tests/test_wcsnrtombs_static.c +++ b/tests/test_wcsnrtombs_static.c | |||
| @@ -15,9 +15,9 @@ int main(int argc, char** argv) { | |||
| 15 | wcsnrtombs(buffer, &srcp, 2, 2, &st); | 15 | wcsnrtombs(buffer, &srcp, 2, 2, &st); |
| 16 | 16 | ||
| 17 | /* Unsafe: ask to write 16 bytes into 4-byte buffer */ | 17 | /* Unsafe: ask to write 16 bytes into 4-byte buffer */ |
| 18 | CHK_FAIL_START | ||
| 19 | srcp = src; | 18 | srcp = src; |
| 20 | memset(&st, 0, sizeof(st)); | 19 | memset(&st, 0, sizeof(st)); |
| 20 | CHK_FAIL_START | ||
| 21 | wcsnrtombs(buffer, &srcp, 10, 16, &st); | 21 | wcsnrtombs(buffer, &srcp, 10, 16, &st); |
| 22 | CHK_FAIL_END | 22 | CHK_FAIL_END |
| 23 | 23 | ||
diff --git a/tests/test_wcsrtombs_dynamic.c b/tests/test_wcsrtombs_dynamic.c new file mode 100644 index 0000000..674a75f --- /dev/null +++ b/tests/test_wcsrtombs_dynamic.c | |||
| @@ -0,0 +1,24 @@ | |||
| 1 | #include "common.h" | ||
| 2 | |||
| 3 | #include <wchar.h> | ||
| 4 | #include <string.h> | ||
| 5 | |||
| 6 | int main(int argc, char** argv) { | ||
| 7 | char buffer[4] = {0}; | ||
| 8 | const wchar_t src[] = L"ABCDEFGHIJ"; | ||
| 9 | const wchar_t *srcp = src; | ||
| 10 | mbstate_t st; | ||
| 11 | memset(&st, 0, sizeof(st)); | ||
| 12 | |||
| 13 | srcp = src; | ||
| 14 | wcsrtombs(buffer, &srcp, 2, &st); | ||
| 15 | |||
| 16 | srcp = src; | ||
| 17 | memset(&st, 0, sizeof(st)); | ||
| 18 | CHK_FAIL_START | ||
| 19 | wcsrtombs(buffer, &srcp, argc + 15, &st); | ||
| 20 | CHK_FAIL_END | ||
| 21 | |||
| 22 | puts(buffer); | ||
| 23 | return ret; | ||
| 24 | } | ||
diff --git a/tests/test_wcsrtombs_static.c b/tests/test_wcsrtombs_static.c new file mode 100644 index 0000000..ffb4919 --- /dev/null +++ b/tests/test_wcsrtombs_static.c | |||
| @@ -0,0 +1,24 @@ | |||
| 1 | #include "common.h" | ||
| 2 | |||
| 3 | #include <wchar.h> | ||
| 4 | #include <string.h> | ||
| 5 | |||
| 6 | int main(int argc, char** argv) { | ||
| 7 | char buffer[4] = {0}; | ||
| 8 | const wchar_t src[] = L"ABCDEFGHIJ"; | ||
| 9 | const wchar_t *srcp = src; | ||
| 10 | mbstate_t st; | ||
| 11 | memset(&st, 0, sizeof(st)); | ||
| 12 | |||
| 13 | srcp = src; | ||
| 14 | wcsrtombs(buffer, &srcp, 2, &st); | ||
| 15 | |||
| 16 | srcp = src; | ||
| 17 | memset(&st, 0, sizeof(st)); | ||
| 18 | CHK_FAIL_START | ||
| 19 | wcsrtombs(buffer, &srcp, 16, &st); | ||
| 20 | CHK_FAIL_END | ||
| 21 | |||
| 22 | puts(buffer); | ||
| 23 | return ret; | ||
| 24 | } | ||
diff --git a/tests/test_wcstombs_dynamic.c b/tests/test_wcstombs_dynamic.c new file mode 100644 index 0000000..6f3962d --- /dev/null +++ b/tests/test_wcstombs_dynamic.c | |||
| @@ -0,0 +1,16 @@ | |||
| 1 | #include "common.h" | ||
| 2 | |||
| 3 | #include <wchar.h> | ||
| 4 | |||
| 5 | int main(int argc, char** argv) { | ||
| 6 | char buffer[4] = {0}; | ||
| 7 | |||
| 8 | wcstombs(buffer, L"AB", 2); | ||
| 9 | |||
| 10 | CHK_FAIL_START | ||
| 11 | wcstombs(buffer, L"ABCDEFGHIJ", argc + 15); | ||
| 12 | CHK_FAIL_END | ||
| 13 | |||
| 14 | puts(buffer); | ||
| 15 | return ret; | ||
| 16 | } | ||
diff --git a/tests/test_wcstombs_static.c b/tests/test_wcstombs_static.c new file mode 100644 index 0000000..5939793 --- /dev/null +++ b/tests/test_wcstombs_static.c | |||
| @@ -0,0 +1,16 @@ | |||
| 1 | #include "common.h" | ||
| 2 | |||
| 3 | #include <wchar.h> | ||
| 4 | |||
| 5 | int main(int argc, char** argv) { | ||
| 6 | char buffer[4] = {0}; | ||
| 7 | |||
| 8 | wcstombs(buffer, L"AB", 2); | ||
| 9 | |||
| 10 | CHK_FAIL_START | ||
| 11 | wcstombs(buffer, L"ABCDEFGHIJ", 16); | ||
| 12 | CHK_FAIL_END | ||
| 13 | |||
| 14 | puts(buffer); | ||
| 15 | return ret; | ||
| 16 | } | ||
