1
0
mirror of https://gitlab.gnome.org/GNOME/libxml2.git synced 2025-10-24 13:33:01 +03:00

Add XPath and XPointer fuzzer

This commit is contained in:
Nick Wellnhofer
2020-08-06 13:20:01 +02:00
parent 956534e02e
commit ad26a60f95
8 changed files with 363 additions and 12 deletions

49
fuzz/xpath.c Normal file
View File

@@ -0,0 +1,49 @@
/*
* xpath.c: a libFuzzer target to test XPath and XPointer expressions.
*
* See Copyright for the status of this software.
*/
#include <libxml/parser.h>
#include <libxml/xpointer.h>
#include "fuzz.h"
int
LLVMFuzzerInitialize(int *argc ATTRIBUTE_UNUSED,
char ***argv ATTRIBUTE_UNUSED) {
xmlInitParser();
xmlSetGenericErrorFunc(NULL, xmlFuzzErrorFunc);
return 0;
}
int
LLVMFuzzerTestOneInput(const char *data, size_t size) {
xmlDocPtr doc;
const char *expr, *xml;
size_t exprSize, xmlSize;
xmlFuzzDataInit(data, size);
expr = xmlFuzzReadString(&exprSize);
xml = xmlFuzzReadString(&xmlSize);
doc = xmlParseMemory(xml, xmlSize);
if (doc != NULL) {
xmlXPathContextPtr xpctxt = xmlXPathNewContext(doc);
/* Resource limits to avoid timeouts and call stack overflows */
xpctxt->maxParserDepth = 15;
xpctxt->maxDepth = 100;
xpctxt->opLimit = 500000;
xmlXPathFreeObject(xmlXPtrEval(BAD_CAST expr, xpctxt));
xmlXPathFreeContext(xpctxt);
}
xmlFreeDoc(doc);
xmlFuzzDataCleanup();
return(0);
}