fuzzer, clientsession: fix build

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
pull/8800/merge
Miklos Vajna 2024-05-10 14:56:37 +02:00 committed by Caolán McNamara
parent 60598961cd
commit 0ef5e740a4
7 changed files with 65 additions and 1 deletions

View File

@ -223,6 +223,7 @@ coolforkit_SOURCES += \
common/DummyTraceEventEmitter.cpp
common_fuzzer_sources = \
fuzzer/Common.cpp \
common/DummyTraceEventEmitter.cpp \
$(coolwsd_sources) \
wsd/coolwsd-inproc.cpp \

View File

@ -3,9 +3,13 @@
#include "config.h"
#include "Admin.hpp"
#include <fuzzer/Common.hpp>
extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
{
static bool initialized = fuzzer::DoInitialization();
(void)initialized;
Admin& admin = Admin::instance();
auto handler = std::make_shared<AdminSocketHandler>(&admin);

View File

@ -3,11 +3,14 @@
#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;
}
@ -20,7 +23,7 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
Poco::URI uriPublic;
std::string docKey = "/fuzz/fuzz.odt";
auto docBroker = std::make_shared<DocumentBroker>(DocumentBroker::ChildType::Interactive, uri,
uriPublic, docKey);
uriPublic, docKey, 0, nullptr);
std::shared_ptr<ProtocolHandlerInterface> ws;
std::string id;

32
fuzzer/Common.cpp 100644
View File

@ -0,0 +1,32 @@
/*
* Copyright the Collabora Online contributors.
*
* SPDX-License-Identifier: MPL-2.0
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
#include <fuzzer/Common.hpp>
#include <map>
#include <string>
#include "config.h"
#include <Log.hpp>
namespace fuzzer
{
bool DoInitialization()
{
std::string logLevel("none");
bool withColor = false;
bool logToFile = false;
std::map<std::string, std::string> logProperties;
Log::initialize("wsd", logLevel, withColor, logToFile, logProperties);
return true;
}
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */

16
fuzzer/Common.hpp 100644
View File

@ -0,0 +1,16 @@
/*
* Copyright the Collabora Online contributors.
*
* SPDX-License-Identifier: MPL-2.0
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
namespace fuzzer
{
bool DoInitialization();
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */

View File

@ -33,6 +33,7 @@
#include <net/HttpRequest.hpp>
#include <FileUtil.hpp>
#include <Util.hpp>
#include <fuzzer/Common.hpp>
class HttpRequestTests final
{
@ -125,6 +126,9 @@ public:
extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
{
static bool initialized = fuzzer::DoInitialization();
(void)initialized;
static HttpRequestTests test;
http::Request httpRequest("/inject/" + Util::bytesToHexString(data, size));

View File

@ -3,9 +3,13 @@
#include "config.h"
#include <net/HttpRequest.hpp>
#include <fuzzer/Common.hpp>
extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
{
static bool initialized = fuzzer::DoInitialization();
(void)initialized;
for (size_t i = 0; i < size; ++i)
{
http::Response response;