OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 <stddef.h> | 5 #include <stddef.h> |
6 #include <stdint.h> | 6 #include <stdint.h> |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/strings/string_tokenizer.h" | 10 #include "base/strings/string_tokenizer.h" |
11 | 11 |
12 void GetAllTokens(base::StringTokenizer& t) { | 12 void GetAllTokens(base::StringTokenizer& t) { |
13 while (t.GetNext()) { | 13 while (t.GetNext()) { |
14 (void)t.token(); | 14 (void)t.token(); |
15 } | 15 } |
16 } | 16 } |
17 | 17 |
18 // Entry point for LibFuzzer. | 18 // Entry point for LibFuzzer. |
19 extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { | 19 extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { |
20 if (size < 1) { | 20 if (size < 1) { |
21 return 0; | 21 return 0; |
22 } | 22 } |
23 | 23 |
24 // Allow quote_chars and options to be set. Otherwise full coverage | 24 // Allow quote_chars and options to be set. Otherwise full coverage |
25 // won't be possible since IsQuote, FullGetNext and other functions | 25 // won't be possible since IsQuote, FullGetNext and other functions |
26 // won't be called. | 26 // won't be called. |
27 size_t pattern_size = data[0]; | 27 size_t pattern_size = data[0]; |
28 | 28 |
29 if (pattern_size > size) { | 29 if (pattern_size > size - 1) { |
30 return 0; | 30 return 0; |
31 } | 31 } |
32 | 32 |
33 std::string pattern(reinterpret_cast<const char*>(data + 1), | 33 std::string pattern(reinterpret_cast<const char*>(data + 1), |
34 pattern_size); | 34 pattern_size); |
35 | 35 |
36 std::string input( | 36 std::string input( |
37 reinterpret_cast<const char*>(data + 1 + pattern_size), | 37 reinterpret_cast<const char*>(data + 1 + pattern_size), |
38 size - pattern_size - 1); | 38 size - pattern_size - 1); |
39 | 39 |
(...skipping 10 matching lines...) Expand all Loading... |
50 GetAllTokens(t_options); | 50 GetAllTokens(t_options); |
51 | 51 |
52 | 52 |
53 base::StringTokenizer t_quote_and_options(input, pattern); | 53 base::StringTokenizer t_quote_and_options(input, pattern); |
54 t_quote_and_options.set_quote_chars("\""); | 54 t_quote_and_options.set_quote_chars("\""); |
55 t_quote_and_options.set_options(base::StringTokenizer::RETURN_DELIMS); | 55 t_quote_and_options.set_options(base::StringTokenizer::RETURN_DELIMS); |
56 GetAllTokens(t_quote_and_options); | 56 GetAllTokens(t_quote_and_options); |
57 | 57 |
58 return 0; | 58 return 0; |
59 } | 59 } |
OLD | NEW |