Fix fuzz/ tests for OpenBSD

* fuzz/wget_*_fuzzer.c: Take care when calling exit()
This commit is contained in:
Tim Rühsen 2019-02-19 17:18:42 +01:00
parent 93d21e4217
commit 8d8abcffdf
8 changed files with 32 additions and 28 deletions

View File

@ -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)

View File

@ -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;

View File

@ -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)

View File

@ -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)

View File

@ -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)

View File

@ -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;

View File

@ -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)

View File

@ -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)