diff options
| -rw-r--r-- | .github/workflows/testsuite.yaml | 9 | ||||
| -rw-r--r-- | include/fortify-headers.h | 6 | ||||
| -rw-r--r-- | include/string.h | 3 | ||||
| -rw-r--r-- | tests/Makefile | 34 |
4 files changed, 32 insertions, 20 deletions
diff --git a/.github/workflows/testsuite.yaml b/.github/workflows/testsuite.yaml index c2ca309..fb655e3 100644 --- a/.github/workflows/testsuite.yaml +++ b/.github/workflows/testsuite.yaml | |||
| @@ -35,7 +35,7 @@ jobs: | |||
| 35 | run: make -C tests gcc | 35 | run: make -C tests gcc |
| 36 | - name: Running the testsuite | 36 | - name: Running the testsuite |
| 37 | shell: bash | 37 | shell: bash |
| 38 | run: make -C tests run | grep -zqv FAIL | 38 | run: make -C tests run |
| 39 | 39 | ||
| 40 | clang: | 40 | clang: |
| 41 | runs-on: ubuntu-latest | 41 | runs-on: ubuntu-latest |
| @@ -64,6 +64,9 @@ jobs: | |||
| 64 | - name: Build | 64 | - name: Build |
| 65 | shell: bash | 65 | shell: bash |
| 66 | run: make -C tests clang | 66 | run: make -C tests clang |
| 67 | - name: Running the testsuite | 67 | - name: Running the compile-time testsuite |
| 68 | shell: bash | ||
| 69 | run: make -C tests clang | ||
| 70 | - name: Running the run-time testsuite | ||
| 68 | shell: bash | 71 | shell: bash |
| 69 | run: make -C tests run | grep -zqv FAIL | 72 | run: make -C tests run |
diff --git a/include/fortify-headers.h b/include/fortify-headers.h index 3eaed7c..bc7bf00 100644 --- a/include/fortify-headers.h +++ b/include/fortify-headers.h | |||
| @@ -106,9 +106,9 @@ | |||
| 106 | #define __diagnose_as_builtin(...) | 106 | #define __diagnose_as_builtin(...) |
| 107 | #endif | 107 | #endif |
| 108 | 108 | ||
| 109 | #if __has_attribute (__diagnose_if) | 109 | #if __has_attribute (diagnose_if) |
| 110 | #define __warning_if(cond, msg) __attribute__ ((__diagnose_if (cond, msg, "warning"))) | 110 | #define __warning_if(cond, msg) __attribute__ ((diagnose_if (cond, msg, "warning"))) |
| 111 | #define __error_if(cond, msg) __attribute__ ((__diagnose_if (cond, msg, "error"))) | 111 | #define __error_if(cond, msg) __attribute__ ((diagnose_if (cond, msg, "error"))) |
| 112 | #else | 112 | #else |
| 113 | #define __warning_if(cond, msg) | 113 | #define __warning_if(cond, msg) |
| 114 | #define __error_if(cond, msg) | 114 | #define __error_if(cond, msg) |
diff --git a/include/string.h b/include/string.h index be13cb4..010b7f2 100644 --- a/include/string.h +++ b/include/string.h | |||
| @@ -43,6 +43,7 @@ __access(read_only, 2, 3) | |||
| 43 | __diagnose_as_builtin(__builtin_memcpy, 1, 2, 3) | 43 | __diagnose_as_builtin(__builtin_memcpy, 1, 2, 3) |
| 44 | _FORTIFY_FN(memcpy) void *memcpy(void * _FORTIFY_POS0 __od, | 44 | _FORTIFY_FN(memcpy) void *memcpy(void * _FORTIFY_POS0 __od, |
| 45 | const void * _FORTIFY_POS0 __os, size_t __n) | 45 | const void * _FORTIFY_POS0 __os, size_t __n) |
| 46 | __error_if((__bos(__od, 0) < __n), "'memcpy' called with `n` bigger than the size of `d`.") | ||
| 46 | { | 47 | { |
| 47 | size_t __bd = __bos(__od, 0); | 48 | size_t __bd = __bos(__od, 0); |
| 48 | size_t __bs = __bos(__os, 0); | 49 | size_t __bs = __bos(__os, 0); |
| @@ -72,8 +73,8 @@ _FORTIFY_FN(memmove) void *memmove(void * _FORTIFY_POS0 __d, | |||
| 72 | 73 | ||
| 73 | __access(write_only, 1, 3) | 74 | __access(write_only, 1, 3) |
| 74 | __diagnose_as_builtin(__builtin_memset, 1, 2, 3) | 75 | __diagnose_as_builtin(__builtin_memset, 1, 2, 3) |
| 75 | __warning_if(__c != 0 && __n == 0, "'memset' will set `0` bytes; did you invert the arguments?") | ||
| 76 | _FORTIFY_FN(memset) void *memset(void * _FORTIFY_POS0 __d, int __c, size_t __n) | 76 | _FORTIFY_FN(memset) void *memset(void * _FORTIFY_POS0 __d, int __c, size_t __n) |
| 77 | __warning_if(__c != 0 && __n == 0, "'memset' will set `0` bytes; did you invert the arguments?") | ||
| 77 | { | 78 | { |
| 78 | size_t __b = __bos(__d, 0); | 79 | size_t __b = __bos(__d, 0); |
| 79 | 80 | ||
diff --git a/tests/Makefile b/tests/Makefile index b14fd6b..4e5ee00 100644 --- a/tests/Makefile +++ b/tests/Makefile | |||
| @@ -1,6 +1,11 @@ | |||
| 1 | CFLAGS=-I../include/ -D_FORTIFY_SOURCE=3 -static -O2 | 1 | CFLAGS=-I../include/ -D_FORTIFY_SOURCE=3 -static -O2 |
| 2 | 2 | ||
| 3 | TARGETS= \ | 3 | COMPTIME_TARGETS= \ |
| 4 | test_memcpy_overwrite_under \ | ||
| 5 | test_memcpy_static_write \ | ||
| 6 | |||
| 7 | |||
| 8 | RUNTIME_TARGETS= \ | ||
| 4 | test_FD_CLR_SETSIZE \ | 9 | test_FD_CLR_SETSIZE \ |
| 5 | test_FD_CLR_negative \ | 10 | test_FD_CLR_negative \ |
| 6 | test_FD_SET_SETSIZE \ | 11 | test_FD_SET_SETSIZE \ |
| @@ -42,9 +47,7 @@ TARGETS= \ | |||
| 42 | test_memcpy_dynamic_read \ | 47 | test_memcpy_dynamic_read \ |
| 43 | test_memcpy_dynamic_write \ | 48 | test_memcpy_dynamic_write \ |
| 44 | test_memcpy_overwrite_over \ | 49 | test_memcpy_overwrite_over \ |
| 45 | test_memcpy_overwrite_under \ | ||
| 46 | test_memcpy_static_read \ | 50 | test_memcpy_static_read \ |
| 47 | test_memcpy_static_write \ | ||
| 48 | test_memmove_dynamic_read \ | 51 | test_memmove_dynamic_read \ |
| 49 | test_memmove_dynamic_write \ | 52 | test_memmove_dynamic_write \ |
| 50 | test_memmove_static_read \ | 53 | test_memmove_static_read \ |
| @@ -124,37 +127,42 @@ TARGETS= \ | |||
| 124 | .SILENT: | 127 | .SILENT: |
| 125 | 128 | ||
| 126 | gcc: CC=../x86_64-linux-musl-native/bin/gcc | 129 | gcc: CC=../x86_64-linux-musl-native/bin/gcc |
| 127 | gcc: $(TARGETS) | 130 | gcc: $(RUNTIME_TARGETS) |
| 128 | 131 | ||
| 129 | clang: CC=clang | 132 | clang: CC=clang |
| 130 | clang: GCOV=gcov | ||
| 131 | clang: CFLAGS+=-I/usr/include/x86_64-linux-musl | 133 | clang: CFLAGS+=-I/usr/include/x86_64-linux-musl |
| 132 | clang: CFLAGS+=-I../x86_64-linux-musl-native/include/ | 134 | clang: CFLAGS+=-I../x86_64-linux-musl-native/include/ |
| 133 | clang: CFLAGS+=-Ix86_64-linux-musl-native/include/ | 135 | clang: CFLAGS+=-Ix86_64-linux-musl-native/include/ |
| 134 | clang: CFLAGS+=-nostdinc | 136 | clang: CFLAGS+=-nostdinc |
| 135 | clang: $(TARGETS) | 137 | clang: comptime $(RUNTIME_TARGETS) |
| 136 | |||
| 137 | all: gcc | ||
| 138 | 138 | ||
| 139 | coverage: CFLAGS += -fprofile-arcs -ftest-coverage | 139 | coverage: CFLAGS += -fprofile-arcs -ftest-coverage |
| 140 | coverage: CC=../x86_64-linux-musl-native/bin/gcc | 140 | coverage: CC=../x86_64-linux-musl-native/bin/gcc |
| 141 | coverage: GCOV=../x86_64-linux-musl-native/bin/gcov | 141 | coverage: GCOV=../x86_64-linux-musl-native/bin/gcov |
| 142 | coverage: $(TARGETS) run | 142 | coverage: $(RUNTIME_TARGETS) run |
| 143 | $(GCOV) *.c | 143 | $(GCOV) *.c |
| 144 | lcov --capture --directory . --output-file coverage.info | 144 | lcov --capture --directory . --output-file coverage.info |
| 145 | lcov --remove ./coverage.info "*/tests/*" --output-file cleaned-coverage.info | 145 | lcov --remove ./coverage.info "*/tests/*" --output-file cleaned-coverage.info |
| 146 | genhtml cleaned-coverage.info --output-directory coverage | 146 | genhtml cleaned-coverage.info --output-directory coverage |
| 147 | 147 | ||
| 148 | $(TARGETS): %: %.c | 148 | all: gcc |
| 149 | |||
| 150 | |||
| 151 | $(RUNTIME_TARGETS): %: %.c | ||
| 149 | $(CC) $(CFLAGS) -o $@ $< | 152 | $(CC) $(CFLAGS) -o $@ $< |
| 150 | 153 | ||
| 151 | run: $(TARGETS) | 154 | run: $(RUNTIME_TARGETS) |
| 152 | $(foreach EXE, $(TARGETS), \ | 155 | $(foreach EXE, $(RUNTIME_TARGETS), \ |
| 153 | timeout 1s ./$(EXE) 1234567890 2 3 4 5 6 7 8 9 0 >/dev/null && echo "$(EXE) OK" || echo "$(EXE) FAIL"; \ | 156 | timeout 1s ./$(EXE) 1234567890 2 3 4 5 6 7 8 9 0 >/dev/null && echo "$(EXE) OK" || echo "$(EXE) FAIL"; \ |
| 154 | ) | 157 | ) |
| 155 | 158 | ||
| 159 | comptime: # only works on clang, as gcc doesn't have the diagnose_if attribute | ||
| 160 | $(foreach EXE, $(COMPTIME_TARGETS), \ | ||
| 161 | ($(CC) $(CFLAGS) -o ./$(EXE) ./$(EXE).c 1>/dev/null 2>/dev/null && echo "$(EXE) FAIL" || echo "$(EXE) OK") || true ;\ | ||
| 162 | ) | ||
| 163 | |||
| 156 | clean: | 164 | clean: |
| 157 | $(foreach EXE, $(TARGETS), \ | 165 | $(foreach EXE, $(RUNTIME_TARGETS) $(COMPTIME_TARGETS), \ |
| 158 | rm -f ./$(EXE) \ | 166 | rm -f ./$(EXE) \ |
| 159 | ) | 167 | ) |
| 160 | rm -rf ./*.gcno ./*.gcda ./*.gcov ./coverage.info ./coverage | 168 | rm -rf ./*.gcno ./*.gcda ./*.gcov ./coverage.info ./coverage |
