Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions tests/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@ RUNTIME_TARGETS= \
test_getlogin_r_static \
test_memcpy_dynamic_read \
test_memcpy_dynamic_write \
test_memcpy_overlap \
test_memcpy_static_read \
test_memcpy_static_write \
test_memmove_dynamic_read \
test_memmove_dynamic_write \
test_memmove_static_read \
Expand All @@ -53,7 +55,9 @@ RUNTIME_TARGETS= \
test_memset_static_write \
test_mbsnrtowcs_dynamic \
test_mbsnrtowcs_static \
test_mbsrtowcs_dynamic \
test_mbsrtowcs_static \
test_mbstowcs_dynamic \
test_mbstowcs_static \
test_poll_dynamic \
test_poll_static \
Expand All @@ -77,6 +81,7 @@ RUNTIME_TARGETS= \
test_send_static \
test_sendto_dynamic \
test_sendto_static \
test_snprintf_dynamic \
test_snprintf_static \
test_sprintf \
test_sprintf_62 \
Expand Down Expand Up @@ -105,6 +110,7 @@ RUNTIME_TARGETS= \
test_swab_dynamic_write \
test_swab_negative \
test_swab_static_read \
test_swab_static_write \
test_ttyname_r_dynamic \
test_ttyname_r_static \
test_vsnprintf_dynamic \
Expand All @@ -113,16 +119,22 @@ RUNTIME_TARGETS= \
test_wcrtomb \
test_wcsnrtombs_dynamic \
test_wcsnrtombs_static \
test_wcscat_dynamic_write \
test_wcscat_static_write \
test_wcscpy_dynamic_write \
test_wcscpy_static_write \
test_wcsncat_dynamic_write \
test_wcsncat_n_eq_buf \
test_wcsncat_n_gt_buf \
test_wcsncat_n_lt_buf \
test_wcsncat_n_one \
test_wcsncat_safe \
test_wcsncat_static_write \
test_wcsncpy_dynamic_write \
test_wcsncpy_static_write \
test_wcsrtombs_dynamic \
test_wcsrtombs_static \
test_wcstombs_dynamic \
test_wcstombs_static \
test_wmemcpy_dynamic_read \
test_wmemcpy_dynamic_write \
Expand Down
6 changes: 3 additions & 3 deletions tests/test_confstr_static.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
#include <unistd.h>

int main(int argc, char** argv) {
char buffer[12] = {0};
char buffer[4] = {0};

confstr(_CS_PATH, buffer, 10);
confstr(_CS_PATH, buffer, 4);

CHK_FAIL_START
confstr(_CS_PATH, buffer, 14);
confstr(_CS_PATH, buffer, 8);
CHK_FAIL_END

puts(buffer);
Expand Down
24 changes: 24 additions & 0 deletions tests/test_mbsrtowcs_dynamic.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#include "common.h"

#include <wchar.h>
#include <string.h>

int main(int argc, char** argv) {
wchar_t buffer[4] = {0};
const char *src = "ABCDEFGHIJ";
const char *srcp = src;
mbstate_t st;
memset(&st, 0, sizeof(st));

srcp = src;
mbsrtowcs(buffer, &srcp, 2, &st);

srcp = src;
memset(&st, 0, sizeof(st));
CHK_FAIL_START
mbsrtowcs(buffer, &srcp, argc + 15, &st);
CHK_FAIL_END

printf("%ls\n", buffer);
return ret;
}
16 changes: 16 additions & 0 deletions tests/test_mbstowcs_dynamic.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#include "common.h"

#include <wchar.h>

int main(int argc, char** argv) {
wchar_t buffer[4] = {0};

mbstowcs(buffer, "AB", 2);

CHK_FAIL_START
mbstowcs(buffer, "ABCDEFGHIJ", argc + 15);
CHK_FAIL_END

printf("%ls\n", buffer);
return ret;
}
27 changes: 27 additions & 0 deletions tests/test_memcpy_overlap.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#include "common.h"

#include <string.h>

/* fortify-headers' memcpy traps when src/dst overlap (but not when src == dst).
* This test exercises that overlap-detection branch, which is unique to this
* implementation. The pointer offset is hidden behind a volatile so -Wrestrict
* cannot see the overlap at compile time. */

int main(int argc, char** argv) {
static char buffer[16] = "0123456789ABCDE";
volatile int off = 2; /* hidden from the compiler so -Wrestrict won't see */
char *p = buffer;
char *q = p + off;

/* dst == src: must NOT trap */
memcpy(p, p, 8);
puts(buffer);

/* Overlapping src/dst (dst < src): must trap */
CHK_FAIL_START
memcpy(p, q, 8);
CHK_FAIL_END

puts(buffer);
return ret;
}
16 changes: 0 additions & 16 deletions tests/test_select_dynamic.c

This file was deleted.

16 changes: 0 additions & 16 deletions tests/test_select_static.c

This file was deleted.

18 changes: 18 additions & 0 deletions tests/test_snprintf_dynamic.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#include "common.h"

#include <stdio.h>

int main(int argc, char** argv) {
#if !defined(__clang__)
char buffer[8] = {0};
snprintf(buffer, sizeof(buffer), "%s", "1234567");
puts(buffer);

CHK_FAIL_START
snprintf(buffer, sizeof(buffer) + argc + 3, "%s", "1234567890");
CHK_FAIL_END

puts(buffer);
#endif
return ret;
}
21 changes: 21 additions & 0 deletions tests/test_wcscat_dynamic_write.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#include "common.h"

#include <wchar.h>

int main(int argc, char** argv) {
wchar_t buffer[8] = {0};
wchar_t src[20];
int i;
wcscat(buffer, L"α");

for (i = 0; i < argc; i++)
src[i] = L'A';
src[i] = L'\0';

CHK_FAIL_START
wcscat(buffer, src);
CHK_FAIL_END

printf("%ls\n", buffer);
return ret;
}
22 changes: 22 additions & 0 deletions tests/test_wcscpy_dynamic_write.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#include "common.h"

#include <wchar.h>

int main(int argc, char** argv) {
wchar_t buffer[8] = {0};
wchar_t src[20];
int i;
wcscpy(buffer, L"α");
printf("%ls\n", buffer);

for (i = 0; i < argc; i++)
src[i] = L'A';
src[i] = L'\0';

CHK_FAIL_START
wcscpy(buffer, src);
CHK_FAIL_END

printf("%ls\n", buffer);
return ret;
}
16 changes: 16 additions & 0 deletions tests/test_wcsncat_dynamic_write.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#include "common.h"

#include <wchar.h>

int main(int argc, char** argv) {
wchar_t buffer[8] = {0};
wcsncat(buffer, L"αβγδεζηθικλμνξοπρστυφχψω", 2);
printf("%ls\n", buffer);

CHK_FAIL_START
wcsncat(buffer, L"αβγδεζηθικλμνξοπρστυφχψω", argc + 1336);
CHK_FAIL_END

printf("%ls\n", buffer);
return ret;
}
16 changes: 16 additions & 0 deletions tests/test_wcsncpy_dynamic_write.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#include "common.h"

#include <wchar.h>

int main(int argc, char** argv) {
wchar_t buffer[8] = {0};
wcsncpy(buffer, L"αβγδεζηθικλμνξοπρστυφχψω", 1);
printf("%ls\n", buffer);

CHK_FAIL_START
wcsncpy(buffer, L"αβγδεζηθικλμνξοπρστυφχψω", argc + 1336);
CHK_FAIL_END

printf("%ls\n", buffer);
return ret;
}
24 changes: 24 additions & 0 deletions tests/test_wcsrtombs_dynamic.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#include "common.h"

#include <wchar.h>
#include <string.h>

int main(int argc, char** argv) {
char buffer[4] = {0};
const wchar_t src[] = L"ABCDEFGHIJ";
const wchar_t *srcp = src;
mbstate_t st;
memset(&st, 0, sizeof(st));

srcp = src;
wcsrtombs(buffer, &srcp, 2, &st);

srcp = src;
memset(&st, 0, sizeof(st));
CHK_FAIL_START
wcsrtombs(buffer, &srcp, argc + 15, &st);
CHK_FAIL_END

puts(buffer);
return ret;
}
16 changes: 16 additions & 0 deletions tests/test_wcstombs_dynamic.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#include "common.h"

#include <wchar.h>

int main(int argc, char** argv) {
char buffer[4] = {0};

wcstombs(buffer, L"AB", 2);

CHK_FAIL_START
wcstombs(buffer, L"ABCDEFGHIJ", argc + 15);
CHK_FAIL_END

puts(buffer);
return ret;
}
Loading