Improve fuzzer stability
- Add more calls to xmlInitializeCatalog.
- Call xmlResetLastError after fuzzing each input.
diff --git a/fuzz/html.c b/fuzz/html.c
index b53c402..116b3df 100644
--- a/fuzz/html.c
+++ b/fuzz/html.c
@@ -13,7 +13,9 @@
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 @@
/* Cleanup */
xmlFuzzDataCleanup();
+ xmlResetLastError();
return(0);
}
diff --git a/fuzz/regexp.c b/fuzz/regexp.c
index cfffedd..af1210a 100644
--- a/fuzz/regexp.c
+++ b/fuzz/regexp.c
@@ -40,6 +40,7 @@
xmlFree(str[0]);
xmlFree(str[1]);
+ xmlResetLastError();
return 0;
}
diff --git a/fuzz/schema.c b/fuzz/schema.c
index 7b034ec..689bffe 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 @@
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 @@
xmlSchemaFreeParserCtxt(pctxt);
xmlFuzzDataCleanup();
+ xmlResetLastError();
return(0);
}
diff --git a/fuzz/xml.c b/fuzz/xml.c
index f0dcfcc..8b4c4ef 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 @@
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 @@
exit:
xmlFuzzDataCleanup();
+ xmlResetLastError();
return(0);
}
diff --git a/fuzz/xpath.c b/fuzz/xpath.c
index 4cb29f6..47652bd 100644
--- a/fuzz/xpath.c
+++ b/fuzz/xpath.c
@@ -45,6 +45,7 @@
xmlFreeDoc(doc);
xmlFuzzDataCleanup();
+ xmlResetLastError();
return(0);
}