Chromium Code Reviews| OLD | NEW |
|---|---|
| (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 } | |
| OLD | NEW |