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

Unified Diff: third_party/expat/fuzz/expat_xml_parse_fuzzer.cc

Issue 2000993003: [libfuzzer] Add expat_xml_parse_fuzzer for third_party/expat. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Use isFinal as a variable + adding a comment. Created 4 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 | « third_party/expat/BUILD.gn ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: third_party/expat/fuzz/expat_xml_parse_fuzzer.cc
diff --git a/third_party/expat/fuzz/expat_xml_parse_fuzzer.cc b/third_party/expat/fuzz/expat_xml_parse_fuzzer.cc
new file mode 100644
index 0000000000000000000000000000000000000000..78b6a2d228a3be5751d7b00fe1a336ab847fed4b
--- /dev/null
+++ b/third_party/expat/fuzz/expat_xml_parse_fuzzer.cc
@@ -0,0 +1,63 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include <stddef.h>
+#include <stdint.h>
+
+#include "third_party/expat/files/lib/expat.h"
+
+#include <array>
+
+static void XMLCALL
+startElement(void* userData, const char* name, const char** atts) {
+ int* depthPtr = static_cast<int*>(userData);
+ (void)atts;
+
+ for (int i = 0; i < *depthPtr; i++)
+ (void)name;
+
+ *depthPtr += 1;
+}
+
+
+static void XMLCALL
+endElement(void* userData, const char* name) {
+ int* depthPtr = static_cast<int*>(userData);
+ (void)name;
+
+ *depthPtr -= 1;
+}
+
+
+std::array<const char*, 7> kEncodings = {{ "UTF-16", "UTF-8", "ISO_8859_1",
+ "US_ASCII", "UTF_16BE", "UTF_16LE",
+ nullptr }};
+
+
+// Entry point for LibFuzzer.
+extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
+ for (auto enc : kEncodings) {
+ XML_Parser parser = XML_ParserCreate(enc);
+ if (!parser)
+ return 0;
+
+ int depth = 0;
+ XML_SetUserData(parser, &depth);
+ XML_SetElementHandler(parser, startElement, endElement);
+
+ const char* dataPtr = reinterpret_cast<const char*>(data);
+
+ // Feed the data with two different values of |isFinal| for better coverage.
+ for (int isFinal = 0; isFinal <= 1; ++isFinal) {
+ if (XML_Parse(parser, dataPtr, size, isFinal) == XML_STATUS_ERROR) {
+ XML_ErrorString(XML_GetErrorCode(parser));
+ XML_GetCurrentLineNumber(parser);
+ }
+ }
+
+ XML_ParserFree(parser);
+ }
+
+ return 0;
+}
« no previous file with comments | « third_party/expat/BUILD.gn ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698