/src/crow/tests/fuzz/http_fuzzer.cpp
Line | Count | Source |
1 | | #include <cstdint> |
2 | | #include <fuzzer/FuzzedDataProvider.h> |
3 | | #include "crow.h" |
4 | | |
5 | | struct DummyHandler { |
6 | 0 | void handle_url() {} |
7 | 0 | void handle_header() {} |
8 | 0 | void handle() {} |
9 | 0 | size_t stream_threshold() { return 1024*1024; } |
10 | | }; |
11 | | |
12 | 0 | extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { |
13 | 0 | static crow::SimpleApp app; |
14 | 0 | static bool initialized = false; |
15 | 0 | if (!initialized) { |
16 | 0 | CROW_ROUTE(app, "/test/<string>/<int>") |
17 | 0 | ([](const crow::request& req, std::string a, int b) |
18 | 0 | { |
19 | 0 | return "OK"; |
20 | 0 | }); |
21 | 0 | CROW_ROUTE(app, "/json") |
22 | 0 | ([](const crow::request& req) |
23 | 0 | { |
24 | 0 | auto j = crow::json::load(req.body); |
25 | 0 | if (j) return "JSON"; |
26 | 0 | return "NOT JSON"; |
27 | 0 | }); |
28 | 0 | crow::logger::setLogLevel(crow::LogLevel::CRITICAL); |
29 | 0 | initialized = true; |
30 | 0 | } |
31 | |
|
32 | 0 | DummyHandler dummy; |
33 | 0 | crow::HTTPParser<DummyHandler> parser(&dummy); |
34 | | |
35 | 0 | if (parser.feed(reinterpret_cast<const char*>(data), size)) { |
36 | 0 | parser.done(); |
37 | 0 | crow::response res; |
38 | 0 | app.handle_full(parser.req, res); |
39 | 0 | } |
40 | |
|
41 | 0 | return 0; |
42 | 0 | } |