From b6196371bb62c2a8f3e7d45fcacf0bf73befa2d2 Mon Sep 17 00:00:00 2001 From: Sergey Lyubka Date: Wed, 26 Jun 2019 11:17:39 +0100 Subject: [PATCH 1/3] Lsm PUBLISHED_FROM=18d9d1e6411db84788c527d1c34ad2adc846df00 --- mongoose.c | 1 + src/mg_http.c | 1 + 2 files changed, 2 insertions(+) diff --git a/mongoose.c b/mongoose.c index 9571d574..22da9a51 100644 --- a/mongoose.c +++ b/mongoose.c @@ -6590,6 +6590,7 @@ void mg_http_handler(struct mg_connection *nc, int ev, struct mg_http_multipart_part mp; memset(&mp, 0, sizeof(mp)); mp.status = -1; + mp.user_data = pd->mp_stream.user_data; mp.var_name = pd->mp_stream.var_name; mp.file_name = pd->mp_stream.file_name; mg_call(nc, (pd->endpoint_handler ? pd->endpoint_handler : nc->handler), diff --git a/src/mg_http.c b/src/mg_http.c index ef546c37..9e9d761c 100644 --- a/src/mg_http.c +++ b/src/mg_http.c @@ -756,6 +756,7 @@ void mg_http_handler(struct mg_connection *nc, int ev, struct mg_http_multipart_part mp; memset(&mp, 0, sizeof(mp)); mp.status = -1; + mp.user_data = pd->mp_stream.user_data; mp.var_name = pd->mp_stream.var_name; mp.file_name = pd->mp_stream.file_name; mg_call(nc, (pd->endpoint_handler ? pd->endpoint_handler : nc->handler), From 1a38e910422b82b1b068bb1632dcc5a88da38e22 Mon Sep 17 00:00:00 2001 From: Sergey Lyubka Date: Fri, 12 Jul 2019 10:23:36 +0100 Subject: [PATCH 2/3] Next PUBLISHED_FROM=6fa0be81ce429b8db9e3ed572cb4a876b6fb2693 --- mongoose.c | 2 +- src/mg_http.c | 2 +- test/Makefile | 6 +++++- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/mongoose.c b/mongoose.c index 22da9a51..5c800075 100644 --- a/mongoose.c +++ b/mongoose.c @@ -6289,7 +6289,7 @@ int mg_parse_http(const char *s, int n, struct http_message *hm, int is_req) { } } else { s = mg_skip(s, end, " ", &hm->proto); - if (end - s < 4 || s[3] != ' ') return -1; + if (end - s < 4 || s[0] < '0' || s[0] > '9' || s[3] != ' ') return -1; hm->resp_code = atoi(s); if (hm->resp_code < 100 || hm->resp_code >= 600) return -1; s += 4; diff --git a/src/mg_http.c b/src/mg_http.c index 9e9d761c..2751d51d 100644 --- a/src/mg_http.c +++ b/src/mg_http.c @@ -455,7 +455,7 @@ int mg_parse_http(const char *s, int n, struct http_message *hm, int is_req) { } } else { s = mg_skip(s, end, " ", &hm->proto); - if (end - s < 4 || s[3] != ' ') return -1; + if (end - s < 4 || s[0] < '0' || s[0] > '9' || s[3] != ' ') return -1; hm->resp_code = atoi(s); if (hm->resp_code < 100 || hm->resp_code >= 600) return -1; s += 4; diff --git a/test/Makefile b/test/Makefile index b3457bf9..7bf70a10 100644 --- a/test/Makefile +++ b/test/Makefile @@ -17,7 +17,7 @@ else COMMON_PARENT = $(SRC_DIR) endif -TEST_SOURCES = unit_test.c test_util.c test_main.c +TEST_SOURCES = unit_test.c test_util.c test_main.c fuzz.c AMALGAMATED_SOURCES = ../mongoose.c KRYPTON_PATH = $(REPO_ROOT)/krypton @@ -118,6 +118,10 @@ clean_index_cgi: @echo -e "CLEAN\tindex.cgi" @rm -f data/cgi/index.cgi* +fuzz: + $(CC) fuzz.c ../mongoose.c -o /tmp/$@ -fsanitize=fuzzer,address -g -I.. + /tmp/$@ + # Interactive: # docker run -v $(CURDIR)/../..:/cesanta -t -i --entrypoint=/bin/bash cesanta/mongoose_test docker: From ff4649fe42bfe93835a0bac77fbe8ab84c8b36e4 Mon Sep 17 00:00:00 2001 From: Sergey Lyubka Date: Fri, 12 Jul 2019 13:28:20 +0100 Subject: [PATCH 3/3] Better UI PUBLISHED_FROM=50f0cafa84cd06428f0da376d85766dcf62af9da --- test/fuzz.c | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 test/fuzz.c diff --git a/test/fuzz.c b/test/fuzz.c new file mode 100644 index 00000000..7a9b0df6 --- /dev/null +++ b/test/fuzz.c @@ -0,0 +1,8 @@ +#include "mongoose.h" + +int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { + struct http_message req; + mg_parse_http((const char *) data, size, &req, 0); + mg_parse_http((const char *) data, size, &req, 1); + return 0; +}