OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "base/at_exit.h" | 5 #include "base/at_exit.h" |
6 #include "base/command_line.h" | 6 #include "base/command_line.h" |
7 #include "base/file_util.h" | 7 #include "base/file_util.h" |
8 #include "net/spdy/fuzzing/hpack_fuzz_util.h" | 8 #include "net/spdy/fuzzing/hpack_fuzz_util.h" |
9 | 9 |
10 namespace { | 10 namespace { |
11 | 11 |
12 // Specifies a file having HPACK header sets. | 12 // Specifies a file having HPACK header sets. |
13 const char kFileToParse[] = "file-to-parse"; | 13 const char kFileToParse[] = "file-to-parse"; |
14 | 14 |
15 } // namespace | 15 } // namespace |
16 | 16 |
17 using base::StringPiece; | 17 using base::StringPiece; |
18 using net::HpackFuzzUtil; | 18 using net::HpackFuzzUtil; |
19 using std::string; | 19 using std::string; |
20 | 20 |
21 // Sequentially runs each given length-prefixed header block through | 21 // Sequentially runs each given length-prefixed header block through |
22 // decoding and encoding fuzzing stages (using HpackFuzzUtil). | 22 // decoding and encoding fuzzing stages (using HpackFuzzUtil). |
23 int main(int argc, char** argv) { | 23 int main(int argc, char** argv) { |
24 base::AtExitManager exit_manager; | 24 base::AtExitManager exit_manager; |
25 | 25 |
26 CommandLine::Init(argc, argv); | 26 CommandLine::Init(argc, argv); |
27 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); | 27 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); |
28 | 28 |
29 if (!command_line.HasSwitch(kFileToParse)) { | 29 if (!command_line.HasSwitch(kFileToParse)) { |
30 LOG(ERROR) << "Usage: " << argv[0] | 30 LOG(ERROR) << "Usage: " << argv[0] << " --" << kFileToParse |
31 << " --" << kFileToParse << "=/path/to/file.in"; | 31 << "=/path/to/file.in"; |
32 return -1; | 32 return -1; |
33 } | 33 } |
34 string file_to_parse = command_line.GetSwitchValueASCII(kFileToParse); | 34 string file_to_parse = command_line.GetSwitchValueASCII(kFileToParse); |
35 | 35 |
36 DVLOG(1) << "Reading input from " << file_to_parse; | 36 DVLOG(1) << "Reading input from " << file_to_parse; |
37 HpackFuzzUtil::Input input; | 37 HpackFuzzUtil::Input input; |
38 CHECK(base::ReadFileToString(base::FilePath(file_to_parse), &input.input)); | 38 CHECK(base::ReadFileToString(base::FilePath(file_to_parse), &input.input)); |
39 | 39 |
40 HpackFuzzUtil::FuzzerContext context; | 40 HpackFuzzUtil::FuzzerContext context; |
41 HpackFuzzUtil::InitializeFuzzerContext(&context); | 41 HpackFuzzUtil::InitializeFuzzerContext(&context); |
42 | 42 |
43 size_t block_count = 0; | 43 size_t block_count = 0; |
44 StringPiece block; | 44 StringPiece block; |
45 while (HpackFuzzUtil::NextHeaderBlock(&input, &block)) { | 45 while (HpackFuzzUtil::NextHeaderBlock(&input, &block)) { |
46 HpackFuzzUtil::RunHeaderBlockThroughFuzzerStages(&context, block); | 46 HpackFuzzUtil::RunHeaderBlockThroughFuzzerStages(&context, block); |
47 ++block_count; | 47 ++block_count; |
48 } | 48 } |
49 DVLOG(1) << "Fuzzed " << block_count << " blocks."; | 49 DVLOG(1) << "Fuzzed " << block_count << " blocks."; |
50 return 0; | 50 return 0; |
51 } | 51 } |
OLD | NEW |