forked from CrowCpp/Crow
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhttp_fuzzer.cpp
More file actions
42 lines (37 loc) · 1.11 KB
/
http_fuzzer.cpp
File metadata and controls
42 lines (37 loc) · 1.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#include <cstdint>
#include <fuzzer/FuzzedDataProvider.h>
#include "crow.h"
struct DummyHandler {
void handle_url() {}
void handle_header() {}
void handle() {}
size_t stream_threshold() { return 1024*1024; }
};
extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
static crow::SimpleApp app;
static bool initialized = false;
if (!initialized) {
CROW_ROUTE(app, "/test/<string>/<int>")
([](const crow::request& req, std::string a, int b)
{
return "OK";
});
CROW_ROUTE(app, "/json")
([](const crow::request& req)
{
auto j = crow::json::load(req.body);
if (j) return "JSON";
return "NOT JSON";
});
crow::logger::setLogLevel(crow::LogLevel::CRITICAL);
initialized = true;
}
DummyHandler dummy;
crow::HTTPParser<DummyHandler> parser(&dummy);
if (parser.feed(reinterpret_cast<const char*>(data), size)) {
parser.done();
crow::response res;
app.handle_full(parser.req, res);
}
return 0;
}