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

Unified Diff: test/fuzzer/parser.cc

Issue 2881583002: [fuzzer] Add input validation in the beginning of the parser fuzz target. (Closed)
Patch Set: Created 3 years, 7 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: test/fuzzer/parser.cc
diff --git a/test/fuzzer/parser.cc b/test/fuzzer/parser.cc
index 5870d9cb3b62873c1126c7cfce54c493d3037e5e..b3c3c6ac17cf5d03b988256977f8321b769f4403 100644
--- a/test/fuzzer/parser.cc
+++ b/test/fuzzer/parser.cc
@@ -14,7 +14,52 @@
#include "src/parsing/preparser.h"
#include "test/fuzzer/fuzzer-support.h"
+#include <list>
+#include <cctype>
+
+bool IsValidInput(const uint8_t* data, size_t size) {
+ std::list<char> parentheses;
+ const char* ptr = reinterpret_cast<const char*>(data);
+
+ for (size_t i = 0; i != size; ++i) {
+ // Check that all characters in the data are valid.
+ if (!(std::isspace(ptr[i]) || std::isprint(ptr[i])))
marja 2017/05/17 08:56:20 Coding style nit: if the body is on the next line,
mmoroz 2017/05/17 09:59:15 Done.
+ return false;
+
+ // Check balance of parentheses in the data.
+ switch (ptr[i]) {
+ case '(':
+ case '[':
+ case '{':
+ parentheses.push_back(ptr[i]);
+ break;
+ case ')':
+ if (parentheses.back() != '(')
+ return false;
+ parentheses.pop_back();
+ break;
+ case ']':
+ if (parentheses.back() != '[')
+ return false;
+ parentheses.pop_back();
+ break;
+ case '}':
+ if (parentheses.back() != '{')
+ return false;
+ parentheses.pop_back();
+ break;
+ default:
+ break;
+ }
+ }
+
+ return parentheses.empty();
+}
+
extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
+ if (!IsValidInput(data, size))
marja 2017/05/17 08:56:20 ditto
mmoroz 2017/05/17 09:59:15 Done.
+ return 0;
+
v8_fuzzer::FuzzerSupport* support = v8_fuzzer::FuzzerSupport::Get();
v8::Isolate* isolate = support->GetIsolate();
« 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