Skip to content

Commit f724cfc

Browse files
libevent: extend fuzzing suite (#11052)
Signed-off-by: David Korczynski <[email protected]>
1 parent f3b1a5c commit f724cfc

File tree

4 files changed

+48
-6
lines changed

4 files changed

+48
-6
lines changed

projects/libevent/Dockerfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,6 @@
1717
FROM gcr.io/oss-fuzz-base/base-builder
1818
RUN apt-get update && apt-get install -y cmake make
1919
RUN git clone --depth 1 https://github.com/libevent/libevent.git libevent
20+
RUN git clone --depth 1 https://github.com/google/fuzzing fuzzing
2021
WORKDIR libevent
2122
COPY build.sh *.cc *.c $SRC/

projects/libevent/build.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,3 +44,5 @@ then
4444
./lib/libevent_pthreads.a ./lib/libevent_extra.a \
4545
-o $OUT/fuzz_request
4646
fi
47+
48+
cp $SRC/fuzzing/dictionaries/http.dict $OUT/http_fuzzer2.dict

projects/libevent/http_fuzzer.cc

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,25 @@ extern "C" {
3232
}
3333

3434
extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
35-
if (size < 1) {
35+
if (size < 5) {
3636
return 0;
3737
}
38+
39+
// Decider to determine which request type to parse.
40+
uint8_t decider = data[0];
41+
data++;
42+
size--;
43+
int maxHeaderSize = *(int*)data;
44+
data += 4;
45+
size -= 4;
46+
if (maxHeaderSize < 0) {
47+
return 0;
48+
}
49+
3850
// Prepare in case it's used.
3951
struct evhttp_connection evcon;
4052
evcon.ext_method_cmp = NULL;
53+
evcon.max_headers_size = maxHeaderSize % 2048;
4154

4255
struct evhttp *http_val = NULL;
4356
http_val = evhttp_new(NULL);
@@ -46,11 +59,6 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
4659
}
4760
evcon.http_server = http_val;
4861

49-
// Decider to determine which request type to parse.
50-
uint8_t decider = data[0];
51-
data++;
52-
size--;
53-
5462
FuzzedDataProvider data_provider(data, size);
5563
std::string s1 = data_provider.ConsumeRandomLengthString();
5664

@@ -84,6 +92,18 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
8492
free(encoded);
8593
}
8694

95+
// Minor utils function
96+
evhttp_htmlescape(s1.c_str());
97+
98+
// URI utils
99+
struct evhttp_uri *uri;
100+
uri = evhttp_uri_parse(s1.c_str());
101+
if (uri != NULL) {
102+
char uri_buf[256];
103+
evhttp_uri_join(uri, uri_buf, 256);
104+
evhttp_uri_free(uri);
105+
}
106+
87107
// Cleanup
88108
evhttp_request_free(req);
89109
evbuffer_free(buf);

projects/libevent/utils_fuzzer.cc

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,5 +46,24 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
4646
evutil_freeaddrinfo(addr_info);
4747
}
4848

49+
int portnum=-1;
50+
struct evutil_addrinfo *res = NULL;
51+
struct evutil_addrinfo hints;
52+
53+
memset(&hints, 0, sizeof(hints));
54+
hints.ai_family = PF_UNSPEC;
55+
evutil_getaddrinfo_common_(NULL, s1.c_str(), &hints, &res, &portnum);
56+
if (res != NULL) {
57+
evutil_freeaddrinfo(res);
58+
}
59+
60+
res = NULL;
61+
memset(&hints, 0, sizeof(hints));
62+
hints.ai_family = PF_UNSPEC;
63+
evutil_getaddrinfo_common_(s1.c_str(), NULL, &hints, &res, &portnum);
64+
if (res != NULL) {
65+
evutil_freeaddrinfo(res);
66+
}
67+
4968
return 0;
5069
}

0 commit comments

Comments
 (0)