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

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: Add different encodings + small codestyle fixes. Created 4 years, 6 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 "third_party/expat/files/lib/expat.h"
9
10 #include <array>
11
12 static void XMLCALL
13 startElement(void* userData, const char* name, const char** atts) {
14 int* depthPtr = static_cast<int*>(userData);
15 (void)atts;
16
17 for (int i = 0; i < *depthPtr; i++)
18 (void)name;
19
20 *depthPtr += 1;
21 }
22
23
24 static void XMLCALL
25 endElement(void* userData, const char* name) {
26 int* depthPtr = static_cast<int*>(userData);
27 (void)name;
28
29 *depthPtr -= 1;
30 }
31
32
33 std::array<const char*, 7> kEncodings = {{ "UTF-16", "UTF-8", "ISO_8859_1",
34 "US_ASCII", "UTF_16BE", "UTF_16LE",
35 nullptr }};
36
37
38 // Entry point for LibFuzzer.
39 extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
40 for (auto enc : kEncodings) {
41 XML_Parser parser = XML_ParserCreate(enc);
42 if (!parser)
43 return 0;
44
45 int depth = 0;
46 XML_SetUserData(parser, &depth);
47 XML_SetElementHandler(parser, startElement, endElement);
48
49 const char* dataPtr = reinterpret_cast<const char*>(data);
50
51 if (XML_Parse(parser, dataPtr, size, false) == XML_STATUS_ERROR) {
inferno 2016/05/25 14:16:19 move this false and true into a local isFinal and
mmoroz 2016/05/25 14:27:31 Done. Thanks!
52 XML_ErrorString(XML_GetErrorCode(parser));
53 XML_GetCurrentLineNumber(parser);
54 }
55
56 if (XML_Parse(parser, dataPtr, size, true) == XML_STATUS_ERROR) {
57 XML_ErrorString(XML_GetErrorCode(parser));
58 XML_GetCurrentLineNumber(parser);
59 }
60
61 XML_ParserFree(parser);
62 }
63
64 return 0;
65 }
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