summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNick Wellnhofer <wellnhofer@aevum.de>2021-02-22 21:28:21 +0100
committerNick Wellnhofer <wellnhofer@aevum.de>2021-02-22 22:29:28 +0100
commit85c817a200b188148e78dee8f7c767d80424a86b (patch)
tree69efd4fb9a50bfd305972861c2e2548e1eb12471
parentf9ccb3b818d37f7fc85017bf206e471cb37fbc82 (diff)
downloadlibxml2-85c817a200b188148e78dee8f7c767d80424a86b.tar.gz
Improve fuzzer stability
- Add more calls to xmlInitializeCatalog. - Call xmlResetLastError after fuzzing each input.
-rw-r--r--fuzz/html.c3
-rw-r--r--fuzz/regexp.c1
-rw-r--r--fuzz/schema.c5
-rw-r--r--fuzz/xml.c5
-rw-r--r--fuzz/xpath.c1
5 files changed, 15 insertions, 0 deletions
diff --git a/fuzz/html.c b/fuzz/html.c
index b53c4025..116b3df3 100644
--- a/fuzz/html.c
+++ b/fuzz/html.c
@@ -13,7 +13,9 @@ int
LLVMFuzzerInitialize(int *argc ATTRIBUTE_UNUSED,
char ***argv ATTRIBUTE_UNUSED) {
xmlInitParser();
+#ifdef LIBXML_CATALOG_ENABLED
xmlInitializeCatalog();
+#endif
xmlSetGenericErrorFunc(NULL, xmlFuzzErrorFunc);
return 0;
@@ -73,6 +75,7 @@ LLVMFuzzerTestOneInput(const char *data, size_t size) {
/* Cleanup */
xmlFuzzDataCleanup();
+ xmlResetLastError();
return(0);
}
diff --git a/fuzz/regexp.c b/fuzz/regexp.c
index cfffedd9..af1210aa 100644
--- a/fuzz/regexp.c
+++ b/fuzz/regexp.c
@@ -40,6 +40,7 @@ LLVMFuzzerTestOneInput(const char *data, size_t size) {
xmlFree(str[0]);
xmlFree(str[1]);
+ xmlResetLastError();
return 0;
}
diff --git a/fuzz/schema.c b/fuzz/schema.c
index 7b034eca..689bffe3 100644
--- a/fuzz/schema.c
+++ b/fuzz/schema.c
@@ -4,6 +4,7 @@
* See Copyright for the status of this software.
*/
+#include <libxml/catalog.h>
#include <libxml/xmlschemas.h>
#include "fuzz.h"
@@ -11,6 +12,9 @@ int
LLVMFuzzerInitialize(int *argc ATTRIBUTE_UNUSED,
char ***argv ATTRIBUTE_UNUSED) {
xmlInitParser();
+#ifdef LIBXML_CATALOG_ENABLED
+ xmlInitializeCatalog();
+#endif
xmlSetGenericErrorFunc(NULL, xmlFuzzErrorFunc);
xmlSetExternalEntityLoader(xmlFuzzEntityLoader);
@@ -33,6 +37,7 @@ LLVMFuzzerTestOneInput(const char *data, size_t size) {
xmlSchemaFreeParserCtxt(pctxt);
xmlFuzzDataCleanup();
+ xmlResetLastError();
return(0);
}
diff --git a/fuzz/xml.c b/fuzz/xml.c
index f0dcfcc9..8b4c4efc 100644
--- a/fuzz/xml.c
+++ b/fuzz/xml.c
@@ -4,6 +4,7 @@
* See Copyright for the status of this software.
*/
+#include <libxml/catalog.h>
#include <libxml/parser.h>
#include <libxml/tree.h>
#include <libxml/xmlerror.h>
@@ -15,6 +16,9 @@ int
LLVMFuzzerInitialize(int *argc ATTRIBUTE_UNUSED,
char ***argv ATTRIBUTE_UNUSED) {
xmlInitParser();
+#ifdef LIBXML_CATALOG_ENABLED
+ xmlInitializeCatalog();
+#endif
xmlSetGenericErrorFunc(NULL, xmlFuzzErrorFunc);
xmlSetExternalEntityLoader(xmlFuzzEntityLoader);
@@ -94,6 +98,7 @@ LLVMFuzzerTestOneInput(const char *data, size_t size) {
exit:
xmlFuzzDataCleanup();
+ xmlResetLastError();
return(0);
}
diff --git a/fuzz/xpath.c b/fuzz/xpath.c
index 4cb29f67..47652bd5 100644
--- a/fuzz/xpath.c
+++ b/fuzz/xpath.c
@@ -45,6 +45,7 @@ LLVMFuzzerTestOneInput(const char *data, size_t size) {
xmlFreeDoc(doc);
xmlFuzzDataCleanup();
+ xmlResetLastError();
return(0);
}