1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56
|
#include <stdio.h>
#include <unistd.h>
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#include "ixml.h"
#define kMinInputLength 10
#define kMaxInputLength 5120
int CheckXML(char *filename){
int rc;
DOMString s;
IXML_Document *doc = NULL;
rc = ixmlLoadDocumentEx(filename, &doc);
if (rc != IXML_SUCCESS) {
return rc;
}
s = ixmlPrintDocument(doc);
if (s == NULL || s[0] == '\0') {
ixmlDocument_free(doc);
return 1;
}
ixmlFreeDOMString(s);
ixmlDocument_free(doc);
return 0;
}
extern int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) {
if (Size < kMinInputLength || Size > kMaxInputLength){
return 1;
}
int ret;
char filename[256];
sprintf(filename, "/tmp/libfuzzer.%d", getpid());
FILE *fp = fopen(filename, "wb");
if (!fp) {
return 0;
}
fwrite(Data, Size, 1, fp);
fclose(fp);
ret = CheckXML(filename);
unlink(filename);
return ret;
}
|