diff options
| -rw-r--r-- | .github/workflows/testsuite.yaml | 12 | ||||
| -rw-r--r-- | include/fortify-headers.h | 8 | ||||
| -rw-r--r-- | include/stdio.h | 13 | ||||
| -rw-r--r-- | include/stdlib.h | 1 | ||||
| -rw-r--r-- | tests/Makefile | 5 | ||||
| -rw-r--r-- | tests/test_malloc.c | 7 | ||||
| -rw-r--r-- | tests/test_vsnprintf_dynamic.c | 1 | ||||
| -rw-r--r-- | tests/test_vsnprintf_static.c | 1 | ||||
| -rw-r--r-- | tests/test_vsprintf.c | 1 |
9 files changed, 32 insertions, 17 deletions
diff --git a/.github/workflows/testsuite.yaml b/.github/workflows/testsuite.yaml index 4499452..e44f104 100644 --- a/.github/workflows/testsuite.yaml +++ b/.github/workflows/testsuite.yaml | |||
| @@ -34,6 +34,18 @@ jobs: | |||
| 34 | steps: | 34 | steps: |
| 35 | - name: Checking out the code | 35 | - name: Checking out the code |
| 36 | uses: actions/checkout@v3 | 36 | uses: actions/checkout@v3 |
| 37 | - name: Cache musl toolchain | ||
| 38 | uses: actions/cache@v3 | ||
| 39 | id: cache-musl | ||
| 40 | with: | ||
| 41 | path: x86_64-linux-musl-native | ||
| 42 | key: musl | ||
| 43 | - name: Downloading musl-based toolchain | ||
| 44 | if: steps.cache-musl.outputs.cache-hit != 'true' | ||
| 45 | run: wget --quiet https://musl.cc/x86_64-linux-musl-native.tgz | ||
| 46 | - name: Extracting musl-based toolchain | ||
| 47 | if: steps.cache-musl.outputs.cache-hit != 'true' | ||
| 48 | run: tar xzf ./x86_64-linux-musl-native.tgz | ||
| 37 | - name: Setting up clang version | 49 | - name: Setting up clang version |
| 38 | run: | | 50 | run: | |
| 39 | sudo update-alternatives --install /usr/bin/clang++ clang++ /usr/bin/clang++-${{ matrix.version }} 100 | 51 | sudo update-alternatives --install /usr/bin/clang++ clang++ /usr/bin/clang++-${{ matrix.version }} 100 |
diff --git a/include/fortify-headers.h b/include/fortify-headers.h index dde19a2..18d302b 100644 --- a/include/fortify-headers.h +++ b/include/fortify-headers.h | |||
| @@ -25,7 +25,7 @@ | |||
| 25 | #ifdef __clang__ | 25 | #ifdef __clang__ |
| 26 | 26 | ||
| 27 | /* clang uses overloads; see https://github.com/llvm/llvm-project/issues/53516 */ | 27 | /* clang uses overloads; see https://github.com/llvm/llvm-project/issues/53516 */ |
| 28 | #define _FORTIFY_POSN(n) const __attribute__((__pass_object_size__(n))) | 28 | #define _FORTIFY_POSN(n) const __attribute__((pass_object_size(n))) |
| 29 | /* we can't use extern inline with overloads without making them external */ | 29 | /* we can't use extern inline with overloads without making them external */ |
| 30 | #define _FORTIFY_INLINE static __inline__ \ | 30 | #define _FORTIFY_INLINE static __inline__ \ |
| 31 | __attribute__((__always_inline__,__artificial__,__overloadable__)) | 31 | __attribute__((__always_inline__,__artificial__,__overloadable__)) |
| @@ -38,6 +38,7 @@ | |||
| 38 | 38 | ||
| 39 | #endif /* __clang__ */ | 39 | #endif /* __clang__ */ |
| 40 | 40 | ||
| 41 | /* https://gcc.gnu.org/onlinedocs/gcc/Object-Size-Checking.html */ | ||
| 41 | #define _FORTIFY_POS0 _FORTIFY_POSN(0) | 42 | #define _FORTIFY_POS0 _FORTIFY_POSN(0) |
| 42 | #define _FORTIFY_POS1 _FORTIFY_POSN(1) | 43 | #define _FORTIFY_POS1 _FORTIFY_POSN(1) |
| 43 | #define _FORTIFY_POS2 _FORTIFY_POSN(2) | 44 | #define _FORTIFY_POS2 _FORTIFY_POSN(2) |
| @@ -47,7 +48,6 @@ | |||
| 47 | #define _FORTIFY_FNB(fn) _FORTIFY_ORIG(__USER_LABEL_PREFIX__,fn) | 48 | #define _FORTIFY_FNB(fn) _FORTIFY_ORIG(__USER_LABEL_PREFIX__,fn) |
| 48 | #define _FORTIFY_FN(fn) _FORTIFY_FNB(fn); _FORTIFY_INLINE | 49 | #define _FORTIFY_FN(fn) _FORTIFY_FNB(fn); _FORTIFY_INLINE |
| 49 | 50 | ||
| 50 | |||
| 51 | /* Use __builtin_dynamic_object_size with _FORTIFY_SOURCE>2, if available. */ | 51 | /* Use __builtin_dynamic_object_size with _FORTIFY_SOURCE>2, if available. */ |
| 52 | #if _FORTIFY_SOURCE > 2 && __has_builtin (__builtin_dynamic_object_size) | 52 | #if _FORTIFY_SOURCE > 2 && __has_builtin (__builtin_dynamic_object_size) |
| 53 | /* | 53 | /* |
| @@ -73,7 +73,11 @@ | |||
| 73 | #endif | 73 | #endif |
| 74 | 74 | ||
| 75 | #if __has_attribute (malloc) | 75 | #if __has_attribute (malloc) |
| 76 | #ifdef __clang__ | ||
| 77 | #define __malloc(...) __attribute__ ((malloc)) | ||
| 78 | #else | ||
| 76 | #define __malloc(...) __attribute__ ((malloc, __VA_ARGS__)) | 79 | #define __malloc(...) __attribute__ ((malloc, __VA_ARGS__)) |
| 80 | #endif /* __clang__ */ | ||
| 77 | #else | 81 | #else |
| 78 | #define __malloc(...) | 82 | #define __malloc(...) |
| 79 | #endif | 83 | #endif |
diff --git a/include/stdio.h b/include/stdio.h index 8cdd826..b31299b 100644 --- a/include/stdio.h +++ b/include/stdio.h | |||
| @@ -36,15 +36,13 @@ extern "C" { | |||
| 36 | #undef fread | 36 | #undef fread |
| 37 | #undef fwrite | 37 | #undef fwrite |
| 38 | #undef popen | 38 | #undef popen |
| 39 | #undef tmpfile | ||
| 40 | #undef snprintf | 39 | #undef snprintf |
| 41 | #undef sprintf | 40 | #undef sprintf |
| 42 | #undef vsnprintf | 41 | #undef vsnprintf |
| 43 | #undef vsprintf | 42 | #undef vsprintf |
| 44 | 43 | ||
| 45 | __access(read_only, 2) | 44 | __access(read_only, 2) |
| 46 | __malloc(malloc (fclose, 1)) | 45 | _FORTIFY_FN(fdopen) FILE *fdopen(int __f, const char* _FORTIFY_POS0 __m) |
| 47 | _FORTIFY_FN(fdopen) FILE *fdopen(int __f, const char* __m) | ||
| 48 | { | 46 | { |
| 49 | return __orig_fdopen(__f, __m); | 47 | return __orig_fdopen(__f, __m); |
| 50 | } | 48 | } |
| @@ -60,7 +58,7 @@ _FORTIFY_FN(fgets) char *fgets(char * _FORTIFY_POS0 __s, int __n, FILE *__f) | |||
| 60 | } | 58 | } |
| 61 | 59 | ||
| 62 | __malloc(malloc (fclose, 1)) | 60 | __malloc(malloc (fclose, 1)) |
| 63 | _FORTIFY_FN(fmemopen) FILE *fmemopen(void* __b, size_t __s, const char* __m) | 61 | _FORTIFY_FN(fmemopen) FILE *fmemopen(void* _FORTIFY_POS0 __b, size_t __s, const char* _FORTIFY_POS0 __m) |
| 64 | { | 62 | { |
| 65 | return __orig_fmemopen(__b, __s, __m); | 63 | return __orig_fmemopen(__b, __s, __m); |
| 66 | } | 64 | } |
| @@ -68,7 +66,7 @@ _FORTIFY_FN(fmemopen) FILE *fmemopen(void* __b, size_t __s, const char* __m) | |||
| 68 | __access(read_only, 1) | 66 | __access(read_only, 1) |
| 69 | __access(read_only, 2) | 67 | __access(read_only, 2) |
| 70 | __malloc(malloc (fclose, 1)) | 68 | __malloc(malloc (fclose, 1)) |
| 71 | _FORTIFY_FN(fopen) FILE *fopen(const char* __p, const char* __m) | 69 | _FORTIFY_FN(fopen) FILE *fopen(const char* _FORTIFY_POS0 __p, const char* _FORTIFY_POS0 __m) |
| 72 | { | 70 | { |
| 73 | return __orig_fopen(__p, __m); | 71 | return __orig_fopen(__p, __m); |
| 74 | } | 72 | } |
| @@ -100,16 +98,19 @@ _FORTIFY_FN(fwrite) size_t fwrite(const void * _FORTIFY_POS0 __d, size_t __n, | |||
| 100 | } | 98 | } |
| 101 | 99 | ||
| 102 | __malloc(malloc (pclose, 1)) | 100 | __malloc(malloc (pclose, 1)) |
| 103 | _FORTIFY_FN(popen) FILE *popen(const char* __c, const char* __t) | 101 | _FORTIFY_FN(popen) FILE *popen(const char* _FORTIFY_POS0 __c, const char* _FORTIFY_POS0 __t) |
| 104 | { | 102 | { |
| 105 | return __orig_popen(__c, __t); | 103 | return __orig_popen(__c, __t); |
| 106 | } | 104 | } |
| 107 | 105 | ||
| 106 | #ifndef __clang__ /* FIXME */ | ||
| 107 | #undef tmpfile | ||
| 108 | __malloc(malloc (fclose, 1)) | 108 | __malloc(malloc (fclose, 1)) |
| 109 | _FORTIFY_FN(tmpfile) FILE *tmpfile(void) | 109 | _FORTIFY_FN(tmpfile) FILE *tmpfile(void) |
| 110 | { | 110 | { |
| 111 | return __orig_tmpfile(); | 111 | return __orig_tmpfile(); |
| 112 | } | 112 | } |
| 113 | #endif | ||
| 113 | 114 | ||
| 114 | __access(read_write, 1, 2) | 115 | __access(read_write, 1, 2) |
| 115 | _FORTIFY_FN(vsnprintf) int vsnprintf(char * _FORTIFY_POS0 __s, size_t __n, | 116 | _FORTIFY_FN(vsnprintf) int vsnprintf(char * _FORTIFY_POS0 __s, size_t __n, |
diff --git a/include/stdlib.h b/include/stdlib.h index 6914f02..3f3c3ba 100644 --- a/include/stdlib.h +++ b/include/stdlib.h | |||
| @@ -38,6 +38,7 @@ extern "C" { | |||
| 38 | 38 | ||
| 39 | #undef malloc | 39 | #undef malloc |
| 40 | #undef realloc | 40 | #undef realloc |
| 41 | #undef calloc | ||
| 41 | 42 | ||
| 42 | __malloc(malloc (free, 1)) | 43 | __malloc(malloc (free, 1)) |
| 43 | __alloc_size(1) | 44 | __alloc_size(1) |
diff --git a/tests/Makefile b/tests/Makefile index c2bc378..8db2853 100644 --- a/tests/Makefile +++ b/tests/Makefile | |||
| @@ -31,7 +31,6 @@ TARGETS= \ | |||
| 31 | test_gethostname_static \ | 31 | test_gethostname_static \ |
| 32 | test_getlogin_r_dynamic \ | 32 | test_getlogin_r_dynamic \ |
| 33 | test_getlogin_r_static \ | 33 | test_getlogin_r_static \ |
| 34 | test_malloc \ | ||
| 35 | test_memchr_dynamic_read \ | 34 | test_memchr_dynamic_read \ |
| 36 | test_memchr_static_read \ | 35 | test_memchr_static_read \ |
| 37 | test_memcpy_dynamic_read \ | 36 | test_memcpy_dynamic_read \ |
| @@ -103,7 +102,9 @@ gcc: clean all | |||
| 103 | clang: CC=clang | 102 | clang: CC=clang |
| 104 | clang: GCOV=gcov | 103 | clang: GCOV=gcov |
| 105 | clang: CFLAGS+=-I/usr/include/x86_64-linux-musl | 104 | clang: CFLAGS+=-I/usr/include/x86_64-linux-musl |
| 106 | clang: CLFAGS+=-nostdlib | 105 | clang: CFLAGS+=-I../x86_64-linux-musl-native/include/ |
| 106 | clang: CFLAGS+=-Ix86_64-linux-musl-native/include/ | ||
| 107 | clang: CFLAGS+=-nostdinc | ||
| 107 | clang: clean all | 108 | clang: clean all |
| 108 | 109 | ||
| 109 | 110 | ||
diff --git a/tests/test_malloc.c b/tests/test_malloc.c deleted file mode 100644 index 360ee82..0000000 --- a/tests/test_malloc.c +++ /dev/null | |||
| @@ -1,7 +0,0 @@ | |||
| 1 | #include "common.h" | ||
| 2 | |||
| 3 | #include <stdlib.h> | ||
| 4 | |||
| 5 | int main(int argc, char** argv) { | ||
| 6 | free(malloc(1)); | ||
| 7 | } | ||
diff --git a/tests/test_vsnprintf_dynamic.c b/tests/test_vsnprintf_dynamic.c index 5d99081..474ba26 100644 --- a/tests/test_vsnprintf_dynamic.c +++ b/tests/test_vsnprintf_dynamic.c | |||
| @@ -10,6 +10,7 @@ int msg_valid(int n, const char * format, ... ) { | |||
| 10 | va_start (args, format); | 10 | va_start (args, format); |
| 11 | vsnprintf(buffer, n, format, args); | 11 | vsnprintf(buffer, n, format, args); |
| 12 | va_end (args); | 12 | va_end (args); |
| 13 | return 0; | ||
| 13 | } | 14 | } |
| 14 | 15 | ||
| 15 | int msg(int n, const char * format, ... ) { | 16 | int msg(int n, const char * format, ... ) { |
diff --git a/tests/test_vsnprintf_static.c b/tests/test_vsnprintf_static.c index f1263a8..d6b7e9b 100644 --- a/tests/test_vsnprintf_static.c +++ b/tests/test_vsnprintf_static.c | |||
| @@ -10,6 +10,7 @@ int msg_valid(int n, const char * format, ... ) { | |||
| 10 | va_start (args, format); | 10 | va_start (args, format); |
| 11 | vsnprintf(buffer, n, format, args); | 11 | vsnprintf(buffer, n, format, args); |
| 12 | va_end (args); | 12 | va_end (args); |
| 13 | return 0; | ||
| 13 | } | 14 | } |
| 14 | 15 | ||
| 15 | int msg(int n, const char * format, ... ) { | 16 | int msg(int n, const char * format, ... ) { |
diff --git a/tests/test_vsprintf.c b/tests/test_vsprintf.c index 4e27201..bd5b893 100644 --- a/tests/test_vsprintf.c +++ b/tests/test_vsprintf.c | |||
| @@ -10,6 +10,7 @@ int msg_valid(const char * format, ... ) { | |||
| 10 | va_start (args, format); | 10 | va_start (args, format); |
| 11 | vsprintf(buffer, format, args); | 11 | vsprintf(buffer, format, args); |
| 12 | va_end (args); | 12 | va_end (args); |
| 13 | return 0; | ||
| 13 | } | 14 | } |
| 14 | 15 | ||
| 15 | int msg(const char * format, ... ) { | 16 | int msg(const char * format, ... ) { |
