1
0
mirror of https://github.com/mirror/wget.git synced 2025-04-24 04:05:05 +08:00

* fuzz/wget_ftpls_fuzzer.c: Fix fuzzer

This commit is contained in:
Tim Rühsen 2019-03-03 17:05:44 +01:00
parent 7c1c8eb3b1
commit acef0fb4c6

View File

@ -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 <dlfcn.h> // 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;
}