summaryrefslogtreecommitdiff
path: root/fuzz/fuzz.c
diff options
context:
space:
mode:
authorNick Wellnhofer <wellnhofer@aevum.de>2020-08-24 03:16:25 +0200
committerNick Wellnhofer <wellnhofer@aevum.de>2020-08-24 03:57:03 +0200
commit0d9da0290c0230802b31f9d9318ec0711ef0c43a (patch)
tree81d464b222b0026cf2162d97b6e46be1abcdd566 /fuzz/fuzz.c
parent3fcf319378f9396a9ca840cd63b96a441818e1f1 (diff)
downloadlibxml2-0d9da0290c0230802b31f9d9318ec0711ef0c43a.tar.gz
Test fuzz targets with dummy driver
Run fuzz targets with files in seed corpus during test.
Diffstat (limited to 'fuzz/fuzz.c')
-rw-r--r--fuzz/fuzz.c32
1 files changed, 32 insertions, 0 deletions
diff --git a/fuzz/fuzz.c b/fuzz/fuzz.c
index 0155efe5..543235c4 100644
--- a/fuzz/fuzz.c
+++ b/fuzz/fuzz.c
@@ -4,8 +4,11 @@
* See Copyright for the status of this software.
*/
+#include <stdio.h>
#include <stdlib.h>
#include <string.h>
+#include <sys/stat.h>
+
#include <libxml/hash.h>
#include <libxml/parser.h>
#include <libxml/parserInternals.h>
@@ -361,3 +364,32 @@ xmlFuzzExtractStrings(const char *data, size_t size, char **strings,
return(ret);
}
+char *
+xmlSlurpFile(const char *path, size_t *sizeRet) {
+ FILE *file;
+ struct stat statbuf;
+ char *data;
+ size_t size;
+
+ if ((stat(path, &statbuf) != 0) || (!S_ISREG(statbuf.st_mode)))
+ return(NULL);
+ size = statbuf.st_size;
+ file = fopen(path, "rb");
+ if (file == NULL)
+ return(NULL);
+ data = xmlMalloc(size + 1);
+ if (data != NULL) {
+ if (fread(data, 1, size, file) != size) {
+ xmlFree(data);
+ data = NULL;
+ } else {
+ data[size] = 0;
+ if (sizeRet != NULL)
+ *sizeRet = size;
+ }
+ }
+ fclose(file);
+
+ return(data);
+}
+