diff options
author | Tim Rühsen <tim.ruehsen@gmx.de> | 2019-02-19 17:18:42 +0100 |
---|---|---|
committer | Tim Rühsen <tim.ruehsen@gmx.de> | 2019-02-19 17:18:49 +0100 |
commit | 8d8abcffdfd5511870016e4f7591117eca4f0122 (patch) | |
tree | e70e4652b234ecde10205eb077e7e56daeda9bb9 /fuzz | |
parent | 93d21e4217265a10c459ccaf0a9d708080aab359 (diff) | |
download | wget-8d8abcffdfd5511870016e4f7591117eca4f0122.tar.gz |
Fix fuzz/ tests for OpenBSD
* fuzz/wget_*_fuzzer.c: Take care when calling exit()
Diffstat (limited to 'fuzz')
-rw-r--r-- | fuzz/wget_cookie_fuzzer.c | 4 | ||||
-rw-r--r-- | fuzz/wget_css_fuzzer.c | 18 | ||||
-rw-r--r-- | fuzz/wget_ftpls_fuzzer.c | 4 | ||||
-rw-r--r-- | fuzz/wget_html_fuzzer.c | 4 | ||||
-rw-r--r-- | fuzz/wget_netrc_fuzzer.c | 4 | ||||
-rw-r--r-- | fuzz/wget_options_fuzzer.c | 18 | ||||
-rw-r--r-- | fuzz/wget_robots_fuzzer.c | 4 | ||||
-rw-r--r-- | fuzz/wget_url_fuzzer.c | 4 |
8 files changed, 32 insertions, 28 deletions
diff --git a/fuzz/wget_cookie_fuzzer.c b/fuzz/wget_cookie_fuzzer.c index 9ff691b6..cf27c614 100644 --- a/fuzz/wget_cookie_fuzzer.c +++ b/fuzz/wget_cookie_fuzzer.c @@ -62,10 +62,6 @@ FILE *fopen_wgetrc(const char *pathname, const char *mode) void exit_wget(int status) { } -#else -void exit(int status) -{ -} #endif int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) diff --git a/fuzz/wget_css_fuzzer.c b/fuzz/wget_css_fuzzer.c index 794e0135..d2d8b09b 100644 --- a/fuzz/wget_css_fuzzer.c +++ b/fuzz/wget_css_fuzzer.c @@ -67,16 +67,26 @@ FILE *fopen_wgetrc(const char *pathname, const char *mode) #endif } +static int do_jump; static jmp_buf jmpbuf; #ifdef FUZZING void exit_wget(int status) { longjmp(jmpbuf, 1); } -#else +#elif defined HAVE_DLFCN_H +#include <dlfcn.h> // dlsym +#ifndef RTLD_NEXT +#define RTLD_NEXT RTLD_GLOBAL +#endif void exit(int status) { - longjmp(jmpbuf, 1); + if (do_jump) { + longjmp(jmpbuf, 1); + } else { + void (*libc_exit)(int) = (void(*)(int)) dlsym (RTLD_NEXT, "exit"); + libc_exit(status); + } } #endif @@ -93,6 +103,8 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) CLOSE_STDERR + do_jump = 1; + if (setjmp(jmpbuf)) goto done; @@ -101,6 +113,8 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) free((void *) ctx.parent_base); done: + do_jump = 0; + RESTORE_STDERR return 0; diff --git a/fuzz/wget_ftpls_fuzzer.c b/fuzz/wget_ftpls_fuzzer.c index bdc0d274..857b6a32 100644 --- a/fuzz/wget_ftpls_fuzzer.c +++ b/fuzz/wget_ftpls_fuzzer.c @@ -63,10 +63,6 @@ FILE *fopen_wgetrc(const char *pathname, const char *mode) void exit_wget(int status) { } -#else -void exit(int status) -{ -} #endif int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) diff --git a/fuzz/wget_html_fuzzer.c b/fuzz/wget_html_fuzzer.c index 70162b1b..75c8153d 100644 --- a/fuzz/wget_html_fuzzer.c +++ b/fuzz/wget_html_fuzzer.c @@ -72,10 +72,6 @@ FILE *fopen_wgetrc(const char *pathname, const char *mode) void exit_wget(int status) { } -#else -void exit(int status) -{ -} #endif int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) diff --git a/fuzz/wget_netrc_fuzzer.c b/fuzz/wget_netrc_fuzzer.c index 20f6c32f..631c3d5e 100644 --- a/fuzz/wget_netrc_fuzzer.c +++ b/fuzz/wget_netrc_fuzzer.c @@ -62,10 +62,6 @@ FILE *fopen_wgetrc(const char *pathname, const char *mode) void exit_wget(int status) { } -#else -void exit(int status) -{ -} #endif int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) diff --git a/fuzz/wget_options_fuzzer.c b/fuzz/wget_options_fuzzer.c index d3063701..9813ab48 100644 --- a/fuzz/wget_options_fuzzer.c +++ b/fuzz/wget_options_fuzzer.c @@ -60,16 +60,26 @@ FILE *fopen_wgetrc(const char *pathname, const char *mode) #endif } +static int do_jump; static jmp_buf jmpbuf; #ifdef FUZZING void exit_wget(int status) { longjmp(jmpbuf, 1); } -#else +#elif defined HAVE_DLFCN_H +#include <dlfcn.h> // dlsym +#ifndef RTLD_NEXT +#define RTLD_NEXT RTLD_GLOBAL +#endif void exit(int status) { - longjmp(jmpbuf, 1); + if (do_jump) { + longjmp(jmpbuf, 1); + } else { + void (*libc_exit)(int) = (void(*)(int)) dlsym (RTLD_NEXT, "exit"); + libc_exit(status); + } } #endif @@ -85,6 +95,8 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) CLOSE_STDERR + do_jump = 1; + if (setjmp(jmpbuf)) goto done; @@ -93,6 +105,8 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) done: cleanup(); + do_jump = 0; + RESTORE_STDERR return 0; diff --git a/fuzz/wget_robots_fuzzer.c b/fuzz/wget_robots_fuzzer.c index bd8100a9..a62e1f5b 100644 --- a/fuzz/wget_robots_fuzzer.c +++ b/fuzz/wget_robots_fuzzer.c @@ -63,10 +63,6 @@ FILE *fopen_wgetrc(const char *pathname, const char *mode) void exit_wget(int status) { } -#else -void exit(int status) -{ -} #endif int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) diff --git a/fuzz/wget_url_fuzzer.c b/fuzz/wget_url_fuzzer.c index 1163f21a..b62ab78f 100644 --- a/fuzz/wget_url_fuzzer.c +++ b/fuzz/wget_url_fuzzer.c @@ -62,10 +62,6 @@ FILE *fopen_wgetrc(const char *pathname, const char *mode) void exit_wget(int status) { } -#else -void exit(int status) -{ -} #endif int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) |