[libxslt] Also search parent dir for source XML when fuzzing
- From: Nick Wellnhofer <nwellnhof src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [libxslt] Also search parent dir for source XML when fuzzing
- Date: Fri, 10 Jan 2020 12:35:13 +0000 (UTC)
commit db4b4e56f088d902b6941bd22dabf3a608c7bd97
Author: Nick Wellnhofer <wellnhofer aevum de>
Date: Fri Jan 10 12:56:13 2020 +0100
Also search parent dir for source XML when fuzzing
This should solve problems when fuzzing a shared library build where
binaries are placed in .libs.
tests/fuzz/fuzz.c | 21 ++++++++++++++++++---
1 file changed, 18 insertions(+), 3 deletions(-)
---
diff --git a/tests/fuzz/fuzz.c b/tests/fuzz/fuzz.c
index d862242c..f502ca2c 100644
--- a/tests/fuzz/fuzz.c
+++ b/tests/fuzz/fuzz.c
@@ -77,6 +77,10 @@ xsltFuzzLoadDoc(const char *argv0, const char *dir, const char *filename) {
if (dir != NULL) {
path = malloc(strlen(dir) + 1 + strlen(filename) + 1);
sprintf(path, "%s/%s", dir, filename);
+ doc = xmlReadFile(path, NULL, 0);
+ if (doc == NULL)
+ fprintf(stderr, "Error: unable to parse file '%s' in '%s'\n",
+ filename, dir);
} else {
const char *end;
size_t dirLen;
@@ -87,11 +91,22 @@ xsltFuzzLoadDoc(const char *argv0, const char *dir, const char *filename) {
memcpy(path, argv0, dirLen);
path[dirLen] = '\0';
strcat(path, filename);
+ doc = xmlReadFile(path, NULL, 0);
+
+ if (doc == NULL && dirLen > 0) {
+ /* Binary might be in .libs, try parent directory */
+ path[dirLen-1] = 0;
+ end = strrchr(path, DIR_SEP);
+ dirLen = (end == NULL) ? 0 : end - path + 1;
+ path[dirLen] = '\0';
+ strcat(path, filename);
+ doc = xmlReadFile(path, NULL, 0);
+ }
+
+ if (doc == NULL)
+ fprintf(stderr, "Error: unable to parse file '%s'\n", filename);
}
- doc = xmlReadFile(path, NULL, 0);
- if (doc == NULL)
- fprintf(stderr, "Error: unable to parse file '%s'\n", path);
free(path);
return doc;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]