From acef0fb4c61d2e8f7830c985ae64fe02248b2382 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim=20R=C3=BChsen?= Date: Sun, 3 Mar 2019 17:05:44 +0100 Subject: [PATCH] * fuzz/wget_ftpls_fuzzer.c: Fix fuzzer --- fuzz/wget_ftpls_fuzzer.c | 34 ++++++++++++++++++++++++++++++---- 1 file changed, 30 insertions(+), 4 deletions(-) diff --git a/fuzz/wget_ftpls_fuzzer.c b/fuzz/wget_ftpls_fuzzer.c index 857b6a32..2b674859 100644 --- a/fuzz/wget_ftpls_fuzzer.c +++ b/fuzz/wget_ftpls_fuzzer.c @@ -59,25 +59,48 @@ FILE *fopen_wgetrc(const char *pathname, const char *mode) return NULL; } +static int do_jump; +static jmp_buf jmpbuf; #ifdef FUZZING void exit_wget(int status) { + longjmp(jmpbuf, 1); +} +#elif defined HAVE_DLFCN_H +#include // dlsym +#ifndef RTLD_NEXT +#define RTLD_NEXT RTLD_GLOBAL +#endif +void exit(int status) +{ + if (do_jump) { + longjmp(jmpbuf, 1); + } else { + void (*libc_exit)(int) = (void(*)(int)) dlsym (RTLD_NEXT, "exit"); + libc_exit(status); + } } #endif int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { +#ifdef HAVE_FMEMOPEN FILE *fp; struct fileinfo *fi; if (size > 4096) // same as max_len = ... in .options file return 0; - CLOSE_STDERR - fp = fmemopen((void *) data, size, "r"); if (!fp) return 0; + CLOSE_STDERR + + do_jump = 1; + + if (setjmp(jmpbuf)) + goto done; + fi = ftp_parse_ls_fp(fp, ST_UNIX); freefileinfo(fi); rewind(fp); @@ -91,11 +114,14 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) rewind(fp); fi = ftp_parse_ls_fp(fp, ST_MACOS); - freefileinfo(fi); +done: + freefileinfo(fi); fclose(fp); - RESTORE_STDERR + do_jump = 0; + RESTORE_STDERR +#endif return 0; }