[libxml2] Fix compiler warnings in fuzzing code
- From: Nick Wellnhofer <nwellnhof src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [libxml2] Fix compiler warnings in fuzzing code
- Date: Fri, 2 Sep 2022 16:52:04 +0000 (UTC)
commit d0ab5c4fe6218ebe49dc20ae53420e79d5ce5aad
Author: Nick Wellnhofer <wellnhofer aevum de>
Date: Fri Sep 2 17:47:48 2022 +0200
Fix compiler warnings in fuzzing code
fuzz/genSeed.c | 17 ++++++++----
fuzz/html.c | 2 +-
fuzz/regexp.c | 3 +--
fuzz/testFuzzer.c | 78 ++++++++++++++++++++++++++++++++-----------------------
4 files changed, 59 insertions(+), 41 deletions(-)
---
diff --git a/fuzz/genSeed.c b/fuzz/genSeed.c
index 01f0656b..dc1c1449 100644
--- a/fuzz/genSeed.c
+++ b/fuzz/genSeed.c
@@ -43,6 +43,8 @@ static struct {
char cwd[PATH_SIZE];
} globalData;
+#if defined(HAVE_SCHEMA_FUZZER) || \
+ defined(HAVE_XML_FUZZER)
/*
* A custom entity loader that writes all external DTDs or entities to a
* single file in the format expected by xmlFuzzEntityLoader.
@@ -94,13 +96,14 @@ fuzzRecorderInit(FILE *out) {
}
static void
-fuzzRecorderCleanup() {
+fuzzRecorderCleanup(void) {
xmlSetExternalEntityLoader(globalData.oldLoader);
xmlHashFree(globalData.entities, xmlHashDefaultDeallocator);
globalData.out = NULL;
globalData.entities = NULL;
globalData.oldLoader = NULL;
}
+#endif
#ifdef HAVE_XML_FUZZER
static int
@@ -169,11 +172,15 @@ processSchema(const char *docFile, FILE *out) {
}
#endif
+#if defined(HAVE_HTML_FUZZER) || \
+ defined(HAVE_SCHEMA_FUZZER) || \
+ defined(HAVE_XML_FUZZER)
static int
processPattern(const char *pattern) {
glob_t globbuf;
int ret = 0;
- int res, i;
+ int res;
+ size_t i;
res = glob(pattern, 0, NULL, &globbuf);
if (res == GLOB_NOMATCH)
@@ -245,6 +252,7 @@ error:
globfree(&globbuf);
return(ret);
}
+#endif
#ifdef HAVE_XPATH_FUZZER
static int
@@ -282,7 +290,7 @@ processXPath(const char *testDir, const char *prefix, const char *name,
continue;
}
- while (fgets(expr, EXPR_SIZE, in) > 0) {
+ while (fgets(expr, EXPR_SIZE, in) != NULL) {
char outPath[PATH_SIZE];
FILE *out;
int j;
@@ -328,7 +336,7 @@ processXPath(const char *testDir, const char *prefix, const char *name,
return(ret);
}
-int
+static int
processXPathDir(const char *testDir) {
char pattern[PATH_SIZE];
glob_t globbuf;
@@ -379,7 +387,6 @@ main(int argc, const char **argv) {
mainFunc processArg = NULL;
const char *fuzzer;
int ret = 0;
- int xpath = 0;
int i;
if (argc < 3) {
diff --git a/fuzz/html.c b/fuzz/html.c
index 116b3df3..ecc6f7a6 100644
--- a/fuzz/html.c
+++ b/fuzz/html.c
@@ -29,7 +29,7 @@ LLVMFuzzerTestOneInput(const char *data, size_t size) {
xmlOutputBufferPtr out;
const char *docBuffer;
size_t docSize, consumed, chunkSize;
- int opts, outSize;
+ int opts;
xmlFuzzDataInit(data, size);
opts = xmlFuzzReadInt();
diff --git a/fuzz/regexp.c b/fuzz/regexp.c
index af1210aa..a0b084a2 100644
--- a/fuzz/regexp.c
+++ b/fuzz/regexp.c
@@ -19,12 +19,11 @@ int
LLVMFuzzerTestOneInput(const char *data, size_t size) {
xmlRegexpPtr regexp;
char *str[2] = { NULL, NULL };
- size_t numStrings;
if (size > 200)
return(0);
- numStrings = xmlFuzzExtractStrings(data, size, str, 2);
+ xmlFuzzExtractStrings(data, size, str, 2);
/* CUR_SCHAR doesn't handle invalid UTF-8 and may cause infinite loops. */
if (xmlCheckUTF8(BAD_CAST str[0]) != 0) {
diff --git a/fuzz/testFuzzer.c b/fuzz/testFuzzer.c
index b0c7ffbc..d14b29be 100644
--- a/fuzz/testFuzzer.c
+++ b/fuzz/testFuzzer.c
@@ -13,51 +13,63 @@
#include "fuzz.h"
#ifdef HAVE_HTML_FUZZER
- #define LLVMFuzzerInitialize fuzzHtmlInit
- #define LLVMFuzzerTestOneInput fuzzHtml
- #include "html.c"
- #undef LLVMFuzzerInitialize
- #undef LLVMFuzzerTestOneInput
+int fuzzHtmlInit(int *argc, char ***argv);
+int fuzzHtml(const char *data, size_t size);
+#define LLVMFuzzerInitialize fuzzHtmlInit
+#define LLVMFuzzerTestOneInput fuzzHtml
+#include "html.c"
+#undef LLVMFuzzerInitialize
+#undef LLVMFuzzerTestOneInput
#endif
#ifdef HAVE_REGEXP_FUZZER
- #define LLVMFuzzerInitialize fuzzRegexpInit
- #define LLVMFuzzerTestOneInput fuzzRegexp
- #include "regexp.c"
- #undef LLVMFuzzerInitialize
- #undef LLVMFuzzerTestOneInput
+int fuzzRegexpInit(int *argc, char ***argv);
+int fuzzRegexp(const char *data, size_t size);
+#define LLVMFuzzerInitialize fuzzRegexpInit
+#define LLVMFuzzerTestOneInput fuzzRegexp
+#include "regexp.c"
+#undef LLVMFuzzerInitialize
+#undef LLVMFuzzerTestOneInput
#endif
#ifdef HAVE_SCHEMA_FUZZER
- #define LLVMFuzzerInitialize fuzzSchemaInit
- #define LLVMFuzzerTestOneInput fuzzSchema
- #include "schema.c"
- #undef LLVMFuzzerInitialize
- #undef LLVMFuzzerTestOneInput
+int fuzzSchemaInit(int *argc, char ***argv);
+int fuzzSchema(const char *data, size_t size);
+#define LLVMFuzzerInitialize fuzzSchemaInit
+#define LLVMFuzzerTestOneInput fuzzSchema
+#include "schema.c"
+#undef LLVMFuzzerInitialize
+#undef LLVMFuzzerTestOneInput
#endif
#ifdef HAVE_URI_FUZZER
- #define LLVMFuzzerInitialize fuzzUriInit
- #define LLVMFuzzerTestOneInput fuzzUri
- #include "uri.c"
- #undef LLVMFuzzerInitialize
- #undef LLVMFuzzerTestOneInput
+int fuzzUriInit(int *argc, char ***argv);
+int fuzzUri(const char *data, size_t size);
+#define LLVMFuzzerInitialize fuzzUriInit
+#define LLVMFuzzerTestOneInput fuzzUri
+#include "uri.c"
+#undef LLVMFuzzerInitialize
+#undef LLVMFuzzerTestOneInput
#endif
#ifdef HAVE_XML_FUZZER
- #define LLVMFuzzerInitialize fuzzXmlInit
- #define LLVMFuzzerTestOneInput fuzzXml
- #include "xml.c"
- #undef LLVMFuzzerInitialize
- #undef LLVMFuzzerTestOneInput
+int fuzzXmlInit(int *argc, char ***argv);
+int fuzzXml(const char *data, size_t size);
+#define LLVMFuzzerInitialize fuzzXmlInit
+#define LLVMFuzzerTestOneInput fuzzXml
+#include "xml.c"
+#undef LLVMFuzzerInitialize
+#undef LLVMFuzzerTestOneInput
#endif
#ifdef HAVE_XPATH_FUZZER
- #define LLVMFuzzerInitialize fuzzXPathInit
- #define LLVMFuzzerTestOneInput fuzzXPath
- #include "xpath.c"
- #undef LLVMFuzzerInitialize
- #undef LLVMFuzzerTestOneInput
+int fuzzXPathInit(int *argc, char ***argv);
+int fuzzXPath(const char *data, size_t size);
+#define LLVMFuzzerInitialize fuzzXPathInit
+#define LLVMFuzzerTestOneInput fuzzXPath
+#include "xpath.c"
+#undef LLVMFuzzerInitialize
+#undef LLVMFuzzerTestOneInput
#endif
typedef int
@@ -71,7 +83,7 @@ static int
testFuzzer(initFunc init, fuzzFunc fuzz, const char *pattern) {
glob_t globbuf;
int ret = -1;
- int i;
+ size_t i;
if (glob(pattern, 0, NULL, &globbuf) != 0) {
fprintf(stderr, "pattern %s matches no files\n", pattern);
@@ -105,7 +117,7 @@ error:
#ifdef HAVE_XML_FUZZER
static int
-testEntityLoader() {
+testEntityLoader(void) {
static const char data[] =
"doc.xml\\\n"
"<!DOCTYPE doc SYSTEM \"doc.dtd\">\n"
@@ -148,7 +160,7 @@ testEntityLoader() {
#endif
int
-main() {
+main(void) {
int ret = 0;
#ifdef HAVE_XML_FUZZER
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]