libreoffice-online/fuzzer/ClientSession.cpp
Miklos Vajna a3fc39e325 libfuzzer: fix build
Also decrease the poll timeout to 0, otherwise testing each input would
now take 5 sec, rather than ~3 ms.

Change-Id: I1a4f347e5ec08a62d40131bfec3c504a19727323
Reviewed-on: https://gerrit.libreoffice.org/c/online/+/95437
Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoffice@gmail.com>
Reviewed-by: Miklos Vajna <vmiklos@collabora.com>
2020-06-03 16:39:45 +02:00

46 lines
1.5 KiB
C++

#include <iostream>
#include "ClientSession.hpp"
bool DoInitialization()
{
LOOLWSD::ChildRoot = "/fuzz/child-root";
return true;
}
extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
{
static bool initialized = DoInitialization();
(void)initialized;
std::string uri;
Poco::URI uriPublic;
std::string docKey = "/fuzz/fuzz.odt";
auto docBroker = std::make_shared<DocumentBroker>(DocumentBroker::ChildType::Interactive, uri,
uriPublic, docKey);
std::shared_ptr<ProtocolHandlerInterface> ws;
std::string id;
bool isReadOnly = false;
Poco::Net::HTTPRequest request(Poco::Net::HTTPRequest::HTTP_GET, uri,
Poco::Net::HTTPMessage::HTTP_1_1);
request.setHost("localhost:9980");
const RequestDetails requestDetails(request, "");
auto session
= std::make_shared<ClientSession>(ws, id, docBroker, uriPublic, isReadOnly, requestDetails);
std::string input(reinterpret_cast<const char*>(data), size);
std::stringstream ss(input);
std::string line;
while (std::getline(ss, line, '\n'))
{
std::vector<char> lineVector(line.data(), line.data() + line.size());
session->handleMessage(lineVector);
}
// Make sure SocketPoll::_newCallbacks does not grow forever, leading to OOM.
Admin::instance().poll(0);
return 0;
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */