Commit 1818bb26 authored by Bailey Berro's avatar Bailey Berro Committed by Commit Bot

Introduce PpdLineReaderFuzzer

This change introduces a fuzzer for the PpdLineReader class that
calls NextLine on random buffers with randon max_line_lengths.

Change-Id: I5aa22e1dbe4fd88a2dee1fed6bd740e3c0fdfad2
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1874593Reviewed-by: default avatarZentaro Kavanagh <zentaro@chromium.org>
Reviewed-by: default avatarSean Kau <skau@chromium.org>
Commit-Queue: Bailey Berro <baileyberro@chromium.org>
Cr-Commit-Position: refs/heads/master@{#709262}
parent 5436defb
......@@ -5,6 +5,7 @@
import("//build/buildflag_header.gni")
import("//build/config/chromeos/rules.gni")
import("//build/config/ui.gni")
import("//testing/libfuzzer/fuzzer_test.gni")
import("//testing/test.gni")
import("//third_party/protobuf/proto_library.gni")
......@@ -266,3 +267,12 @@ if (is_cros_chrome_sdk) {
]
}
}
fuzzer_test("ppd_line_reader_fuzzer") {
sources = [
"printing/ppd_line_reader_fuzzer.cc",
]
deps = [
":chromeos",
]
}
// Copyright 2019 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 "chromeos/printing/ppd_line_reader.h"
#include <memory>
#include <string>
#include <fuzzer/FuzzedDataProvider.h>
namespace {
constexpr int kUpperMaxLineLengthBound = 1024;
} // namespace
namespace chromeos {
extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
FuzzedDataProvider data_provider(data, size);
const size_t line_length =
data_provider.ConsumeIntegralInRange<size_t>(0, kUpperMaxLineLengthBound);
const std::string contents = data_provider.ConsumeRemainingBytesAsString();
std::unique_ptr<PpdLineReader> ppd_line_reader =
PpdLineReader::Create(contents, line_length);
std::string line;
while (ppd_line_reader->NextLine(&line)) {
// Call NextLine() until we hit the end of the file or an error.
}
return 0;
}
} // namespace chromeos
\ No newline at end of file
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment