Skip to content
Draft
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Improve fuzz test coverage
Add fuzz target and corpus for testing ip_representation() API
  • Loading branch information
sgbhat2 committed Dec 13, 2020
commit aa058fe54ea5c4971de04ba0d1258981f88b0902
4 changes: 4 additions & 0 deletions test/fuzz/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,14 @@ make && sudo make install
```
cd libhttpserver/test/fuzz
clang++ $CXXFLAGS basic_fuzzer.cc -o basic_fuzzer -fsanitize=fuzzer,undefined /usr/local/lib/libhttpserver.a /usr/local/lib/libmicrohttpd.a -lgnutls
clang++ $CXXFLAGS ip_representation.cc -o ip_representation -fsanitize=fuzzer,undefined /usr/local/lib/libhttpserver.a /usr/local/lib/libmicrohttpd.a -lgnutls
```

## Run the fuzz target
```
unzip basic_fuzzer_seed_corpus.zip
./basic_fuzzer corpus/

unzip ip_representation_seed_corpus.zip
./ip_representation ip_corpus/
```
10 changes: 10 additions & 0 deletions test/fuzz/basic_fuzzer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,16 @@ class fuzz_resource : public http_resource {
public:
const std::shared_ptr<http_response> render(const http_request& req) {
std::stringstream ss;
req.get_args();
req.get_headers();
req.get_footers();
req.get_cookies();
req.get_querystring();
req.get_user();
req.get_pass();
req.get_digested_user();
req.get_requestor();
req.get_requestor_port();
for (unsigned int i = 0; i < req.get_path_pieces().size(); i++)
ss << req.get_path_piece(i) << ",";
return std::shared_ptr<http_response>(new string_response(ss.str(), 200));
Expand Down
14 changes: 14 additions & 0 deletions test/fuzz/ip_representation.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#include <httpserver.hpp>

using namespace httpserver;
extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
if (!size)
return 0;
std::string str(reinterpret_cast<const char *>(data), size);
try {
http::ip_representation test(str);
} catch (std::exception &e) {
return 0;
}
return 0;
}
Binary file added test/fuzz/ip_representation_seed_corpus.zip
Binary file not shown.