blob: 1ca71c3ab4f5f0f7a282c363d249532b2b59dfaf [file] [log] [blame]
// Copyright 2018 The Chromium OS 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 "shill/net/io_handler.h"
#include "shill/net/rtnl_handler.h"
#include "shill/net/rtnl_listener.h"
#include <base/at_exit.h>
#include <base/bind.h>
#include <base/logging.h>
namespace shill {
class RTNLHandlerFuzz {
public:
static void Run(const uint8_t* data, size_t size) {
base::AtExitManager exit_manager;
InputData input(static_cast<const unsigned char*>(data), size);
// Listen for all messages.
RTNLListener listener(~0, base::Bind(&RTNLHandlerFuzz::Listener));
RTNLHandler::GetInstance()->ParseRTNL(&input);
}
private:
static void Listener(const RTNLMessage& msg) {
CHECK_NE(msg.ToString(), "");
const auto& bytes = msg.Encode();
switch (msg.type()) {
case RTNLMessage::kTypeRdnss:
case RTNLMessage::kTypeDnssl:
// RDNSS and DNSSL (RTM_NEWNDUSEROPT) don't have "query" modes, so we
// don't support re-constructing them in user space.
CHECK(bytes.IsEmpty());
break;
default:
CHECK(!bytes.IsEmpty());
}
}
};
extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
// Turn off logging.
logging::SetMinLogLevel(logging::LOGGING_FATAL);
RTNLHandlerFuzz::Run(data, size);
return 0;
}
} // namespace shill