Fuzz Http in chunks

This commit is contained in:
Alex Hultman
2019-04-03 02:59:24 +02:00
parent af9513e3e4
commit cd00bfc779
3 changed files with 36 additions and 37 deletions
+10 -11
View File
@@ -2,15 +2,14 @@
#define WIN32_EXPORT #define WIN32_EXPORT
#include "helpers.h"
/* We test the websocket parser */ /* We test the websocket parser */
#include "../src/HttpParser.h" #include "../src/HttpParser.h"
/* And the router */ /* And the router */
#include "../src/HttpRouter.h" #include "../src/HttpRouter.h"
/* We use this to pad the fuzz */
char *padded = new char[1024 * 500];
struct StaticData { struct StaticData {
struct RouterData { struct RouterData {
@@ -48,22 +47,21 @@ struct StaticData {
} staticData; } staticData;
extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
/* Create parser */
/* Pad the fuzz */
uWS::HttpParser httpParser; uWS::HttpParser httpParser;
memcpy(padded, data, size);
/* User data */ /* User data */
void *user = (void *) 13; void *user = (void *) 13;
/* Iterate the padded fuzz as chunks */
makeChunked(makePadded(data, size), size, [&httpParser, user](const uint8_t *data, size_t size) {
/* Parse it */ /* Parse it */
httpParser.consumePostPadded(padded, size, user, [](void *s, uWS::HttpRequest *httpRequest) -> void * { httpParser.consumePostPadded((char *) data, size, user, [](void *s, uWS::HttpRequest *httpRequest) -> void * {
/* todo: Route this via router */ /* todo: Route this via router */
httpRequest->getHeader(httpRequest->getUrl()); readBytes(httpRequest->getHeader(httpRequest->getUrl()));
httpRequest->getMethod(); readBytes(httpRequest->getMethod());
httpRequest->getQuery(); readBytes(httpRequest->getQuery());
/* Route the method and URL in two passes */ /* Route the method and URL in two passes */
StaticData::RouterData routerData = {}; StaticData::RouterData routerData = {};
@@ -89,6 +87,7 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
/* Return break */ /* Return break */
return nullptr; return nullptr;
}); });
});
return 0; return 0;
} }
+1 -1
View File
@@ -248,7 +248,7 @@ public:
int maxCopyDistance = std::min(MAX_FALLBACK_SIZE - fallback.length(), (size_t) length); int maxCopyDistance = std::min(MAX_FALLBACK_SIZE - fallback.length(), (size_t) length);
fallback.reserve(maxCopyDistance + 32); // todo: padding should be same as libus fallback.reserve(fallback.length() + maxCopyDistance + 32); // todo: padding should be same as libus
fallback.append(data, maxCopyDistance); fallback.append(data, maxCopyDistance);
// break here on break // break here on break