Set running = 1 before entering the main loop.

This is so the fuzzer can wait for it.
This commit is contained in:
Emil Mikulic 2022-10-02 12:08:57 +11:00
parent 47920915c7
commit 762956f1a8
3 changed files with 5 additions and 4 deletions

View File

@ -308,7 +308,7 @@ static char *auth_key = NULL;
static uint64_t num_requests = 0, total_in = 0, total_out = 0; static uint64_t num_requests = 0, total_in = 0, total_out = 0;
static int accepting = 1; /* set to 0 to stop accept()ing */ static int accepting = 1; /* set to 0 to stop accept()ing */
static int syslog_enabled = 0; static int syslog_enabled = 0;
static volatile int running = 1; /* signal handler sets this to false */ volatile int running = 0; /* signal handler sets this to false */
#define INVALID_UID ((uid_t) -1) #define INVALID_UID ((uid_t) -1)
#define INVALID_GID ((gid_t) -1) #define INVALID_GID ((gid_t) -1)
@ -2847,6 +2847,7 @@ int main(int argc, char **argv) {
if (want_daemon) daemonize_finish(); if (want_daemon) daemonize_finish();
/* main loop */ /* main loop */
running = 1;
while (running) httpd_poll(); while (running) httpd_poll();
/* clean exit */ /* clean exit */

View File

@ -9,6 +9,7 @@
#include <thread> #include <thread>
extern "C" int darkhttpd(int argc, const char** argv); extern "C" int darkhttpd(int argc, const char** argv);
extern "C" volatile int running;
namespace { namespace {
int argc = 4; int argc = 4;
@ -26,8 +27,8 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
addrin.sin_family = AF_INET; addrin.sin_family = AF_INET;
addrin.sin_port = htons(port); addrin.sin_port = htons(port);
if (inet_aton(host, &addrin.sin_addr) == 0) err(1, "inet_aton"); if (inet_aton(host, &addrin.sin_addr) == 0) err(1, "inet_aton");
while (!running) { std::this_thread::yield(); }
inited = true; inited = true;
sleep(1);
} }
char buf[4096]; char buf[4096];

View File

@ -1,7 +1,6 @@
#!/bin/bash -e #!/bin/bash -e
set -x set -x
mkdir -p tmp.fuzz mkdir -p fuzz_socket_testcases
echo hi > tmp.fuzz/hello.txt
clang -c -Dmain=darkhttpd -g -O2 -fsanitize=fuzzer,address ../darkhttpd.c -o fuzz_darkhttpd.o clang -c -Dmain=darkhttpd -g -O2 -fsanitize=fuzzer,address ../darkhttpd.c -o fuzz_darkhttpd.o
clang++ -g -O2 -fsanitize=fuzzer,address fuzz_socket.cc fuzz_darkhttpd.o -o fuzz_socket clang++ -g -O2 -fsanitize=fuzzer,address fuzz_socket.cc fuzz_darkhttpd.o -o fuzz_socket
./fuzz_socket fuzz_socket_testcases -detect_leaks=0 -only_ascii=1 ./fuzz_socket fuzz_socket_testcases -detect_leaks=0 -only_ascii=1