[libxml2] Improve fuzzer stability



commit 85c817a200b188148e78dee8f7c767d80424a86b
Author: Nick Wellnhofer <wellnhofer aevum de>
Date:   Mon Feb 22 21:28:21 2021 +0100

    Improve fuzzer stability
    
    - Add more calls to xmlInitializeCatalog.
    - Call xmlResetLastError after fuzzing each input.

 fuzz/html.c   | 3 +++
 fuzz/regexp.c | 1 +
 fuzz/schema.c | 5 +++++
 fuzz/xml.c    | 5 +++++
 fuzz/xpath.c  | 1 +
 5 files changed, 15 insertions(+)
---
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);
 }


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]