Revert "Fix broken channel icon in chrome://help on CrOS" and try again
[chromium-blink-merge.git] / net / spdy / fuzzing / hpack_fuzz_wrapper.cc
blobf816b1eff62152ecc18765b0489869755e1bd474
1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "base/at_exit.h"
6 #include "base/command_line.h"
7 #include "base/files/file_util.h"
8 #include "net/spdy/fuzzing/hpack_fuzz_util.h"
10 namespace {
12 // Specifies a file having HPACK header sets.
13 const char kFileToParse[] = "file-to-parse";
15 } // namespace
17 using base::StringPiece;
18 using net::HpackFuzzUtil;
19 using std::string;
21 // Sequentially runs each given length-prefixed header block through
22 // decoding and encoding fuzzing stages (using HpackFuzzUtil).
23 int main(int argc, char** argv) {
24 base::AtExitManager exit_manager;
26 base::CommandLine::Init(argc, argv);
27 const base::CommandLine& command_line =
28 *base::CommandLine::ForCurrentProcess();
30 if (!command_line.HasSwitch(kFileToParse)) {
31 LOG(ERROR) << "Usage: " << argv[0]
32 << " --" << kFileToParse << "=/path/to/file.in";
33 return -1;
35 string file_to_parse = command_line.GetSwitchValueASCII(kFileToParse);
37 // ClusterFuzz may invoke as --file-to-parse="". Don't crash in this case.
38 if (file_to_parse.empty()) {
39 LOG(WARNING) << "Empty file to parse given. Doing nothing.";
40 return 0;
43 DVLOG(1) << "Reading input from " << file_to_parse;
44 HpackFuzzUtil::Input input;
45 CHECK(base::ReadFileToString(base::FilePath::FromUTF8Unsafe(file_to_parse),
46 &input.input));
48 HpackFuzzUtil::FuzzerContext context;
49 HpackFuzzUtil::InitializeFuzzerContext(&context);
51 size_t block_count = 0;
52 StringPiece block;
53 while (HpackFuzzUtil::NextHeaderBlock(&input, &block)) {
54 HpackFuzzUtil::RunHeaderBlockThroughFuzzerStages(&context, block);
55 ++block_count;
57 DVLOG(1) << "Fuzzed " << block_count << " blocks.";
58 return 0;