Skip to content

Commit aa058fe

Browse files
committed
Improve fuzz test coverage
Add fuzz target and corpus for testing ip_representation() API
1 parent 03b2d46 commit aa058fe

File tree

4 files changed

+28
-0
lines changed

4 files changed

+28
-0
lines changed

test/fuzz/README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,14 @@ make && sudo make install
2525
```
2626
cd libhttpserver/test/fuzz
2727
clang++ $CXXFLAGS basic_fuzzer.cc -o basic_fuzzer -fsanitize=fuzzer,undefined /usr/local/lib/libhttpserver.a /usr/local/lib/libmicrohttpd.a -lgnutls
28+
clang++ $CXXFLAGS ip_representation.cc -o ip_representation -fsanitize=fuzzer,undefined /usr/local/lib/libhttpserver.a /usr/local/lib/libmicrohttpd.a -lgnutls
2829
```
2930

3031
## Run the fuzz target
3132
```
3233
unzip basic_fuzzer_seed_corpus.zip
3334
./basic_fuzzer corpus/
35+
36+
unzip ip_representation_seed_corpus.zip
37+
./ip_representation ip_corpus/
3438
```

test/fuzz/basic_fuzzer.cc

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,16 @@ class fuzz_resource : public http_resource {
3131
public:
3232
const std::shared_ptr<http_response> render(const http_request& req) {
3333
std::stringstream ss;
34+
req.get_args();
35+
req.get_headers();
36+
req.get_footers();
37+
req.get_cookies();
38+
req.get_querystring();
39+
req.get_user();
40+
req.get_pass();
41+
req.get_digested_user();
42+
req.get_requestor();
43+
req.get_requestor_port();
3444
for (unsigned int i = 0; i < req.get_path_pieces().size(); i++)
3545
ss << req.get_path_piece(i) << ",";
3646
return std::shared_ptr<http_response>(new string_response(ss.str(), 200));

test/fuzz/ip_representation.cc

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#include <httpserver.hpp>
2+
3+
using namespace httpserver;
4+
extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
5+
if (!size)
6+
return 0;
7+
std::string str(reinterpret_cast<const char *>(data), size);
8+
try {
9+
http::ip_representation test(str);
10+
} catch (std::exception &e) {
11+
return 0;
12+
}
13+
return 0;
14+
}
500 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)