0ef5e740a4
Probably went wrong in commit de985834e2
(wsd: simplify DocumentBroker construction, 2024-04-03).
Also init logging to avoid:
common/Log.cpp:664:16: runtime error: downcast of address 0x6070000005d0 which does not point to an object of type 'GenericLogger'
0x6070000005d0: note: object is of type 'Poco::Logger'
similar to how COOLWSD::innerInitialize() does it.
Signed-off-by: Miklos Vajna <vmiklos@collabora.com>
Change-Id: Ic16bb2f070e1f0e12204bcc2fc70303d8c1250c8
58 lines
1.8 KiB
C++
58 lines
1.8 KiB
C++
#include <iostream>
|
|
|
|
#include "config.h"
|
|
|
|
#include "ClientSession.hpp"
|
|
#include <fuzzer/Common.hpp>
|
|
|
|
bool DoInitialization()
|
|
{
|
|
COOLWSD::ChildRoot = "/fuzz/child-root";
|
|
UnitBase::init(UnitBase::UnitType::Wsd, std::string());
|
|
|
|
fuzzer::DoInitialization();
|
|
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, 0, nullptr);
|
|
|
|
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);
|
|
}
|
|
|
|
// The DocumentBroker dtor grows SocketPoll::_newCallbacks.
|
|
docBroker.reset();
|
|
|
|
// Make sure SocketPoll::_newCallbacks does not grow forever, leading to OOM.
|
|
Admin::instance().poll(std::chrono::microseconds(0));
|
|
|
|
// Make sure the anon map does not grow forever, leading to OOM.
|
|
Util::clearAnonymized();
|
|
return 0;
|
|
}
|
|
|
|
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|