[go: nahoru, domu]

blob: f96e5005193d0ec3daa94d59eed2bc3484492c92 [file] [log] [blame]
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include <stddef.h>
#include <stdint.h>
#include <iostream>
#include <memory>
#include <string>
#include "base/check.h"
#include "base/logging.h"
#include "base/no_destructor.h"
#include "third_party/protobuf/src/google/protobuf/stubs/logging.h"
#include "third_party/ukey2/fuzzers/d2d_connection_context_factory.h"
// Disable noisy logging in protobuf.
google::protobuf::LogSilencer log_silencer;
struct Environment {
Environment() {
// Disable noisy logging as per "libFuzzer in Chrome" documentation:
// testing/libfuzzer/getting_started.md#Disable-noisy-error-message-logging.
logging::SetMinLogLevel(logging::LOG_FATAL);
// Disable noisy logging in securemessage.
std::cerr.setstate(std::ios_base::failbit);
// Create instance once to be reused between fuzzing rounds.
server_context = securegcm::CreateServerContext();
CHECK(server_context);
}
std::unique_ptr<securegcm::D2DConnectionContextV1> server_context;
};
extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
static base::NoDestructor<Environment> environment;
std::string buffer(data, data + size);
environment->server_context->DecodeMessageFromPeer(buffer);
return 0;
}