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

Side by Side 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: 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 unified diff | Download patch
« no previous file with comments | « third_party/expat/BUILD.gn ('k') | 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
(Empty)
1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include <stddef.h>
6 #include <stdint.h>
7
8 #include <expat.h>
9
10 static void XMLCALL
11 startElement(void* userData, const char* name, const char** atts) {
12 int *depthPtr = (int *)userData;
13 (void)atts;
14
15 for (int i = 0; i < *depthPtr; i++) {
16 (void)name;
17 }
18
19 *depthPtr += 1;
20 }
21
22 static void XMLCALL
23 endElement(void* userData, const char* name) {
24 int* depthPtr = static_cast<int*>(userData);
25 (void)name;
26
27 *depthPtr -= 1;
28 }
29
30 // Entry point for LibFuzzer.
31 extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
32 XML_Parser parser = XML_ParserCreate(NULL);
mmoroz 2016/05/23 18:06:55 Probably worth to use several possible values for
33 if (!parser)
34 return 0;
35
36 int depth = 0;
37 XML_SetUserData(parser, &depth);
38 XML_SetElementHandler(parser, startElement, endElement);
39
40 const char* dataPtr = reinterpret_cast<const char*>(data);
41
42 if (XML_Parse(parser, dataPtr, size, 1) == XML_STATUS_ERROR) {
43 XML_ErrorString(XML_GetErrorCode(parser));
44 XML_GetCurrentLineNumber(parser);
45 }
46
47 XML_ParserFree(parser);
48 return 0;
49 }
OLDNEW
« 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