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 base::CommandLine::Init(argc, argv); |
27 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); | 27 const base::CommandLine& command_line = |
| 28 *base::CommandLine::ForCurrentProcess(); |
28 | 29 |
29 if (!command_line.HasSwitch(kFileToParse)) { | 30 if (!command_line.HasSwitch(kFileToParse)) { |
30 LOG(ERROR) << "Usage: " << argv[0] | 31 LOG(ERROR) << "Usage: " << argv[0] |
31 << " --" << kFileToParse << "=/path/to/file.in"; | 32 << " --" << kFileToParse << "=/path/to/file.in"; |
32 return -1; | 33 return -1; |
33 } | 34 } |
34 string file_to_parse = command_line.GetSwitchValueASCII(kFileToParse); | 35 string file_to_parse = command_line.GetSwitchValueASCII(kFileToParse); |
35 | 36 |
36 // ClusterFuzz may invoke as --file-to-parse="". Don't crash in this case. | 37 // ClusterFuzz may invoke as --file-to-parse="". Don't crash in this case. |
37 if (file_to_parse.empty()) { | 38 if (file_to_parse.empty()) { |
(...skipping 11 matching lines...) Expand all Loading... |
49 | 50 |
50 size_t block_count = 0; | 51 size_t block_count = 0; |
51 StringPiece block; | 52 StringPiece block; |
52 while (HpackFuzzUtil::NextHeaderBlock(&input, &block)) { | 53 while (HpackFuzzUtil::NextHeaderBlock(&input, &block)) { |
53 HpackFuzzUtil::RunHeaderBlockThroughFuzzerStages(&context, block); | 54 HpackFuzzUtil::RunHeaderBlockThroughFuzzerStages(&context, block); |
54 ++block_count; | 55 ++block_count; |
55 } | 56 } |
56 DVLOG(1) << "Fuzzed " << block_count << " blocks."; | 57 DVLOG(1) << "Fuzzed " << block_count << " blocks."; |
57 return 0; | 58 return 0; |
58 } | 59 } |
OLD | NEW |