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:
49
fuzz/xpath.c
Normal file
49
fuzz/xpath.c
Normal 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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user