Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(194)

Side by Side Diff: testing/libfuzzer/fuzzers/string_tokenizer_fuzzer.cc

Issue 2193283002: [AFL][libFuzzer] Fix read past end of fuzzing target input buffer. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698