libmagic needs magic file to work

This commit is contained in:
Mike Aizatsky 2016-11-04 17:04:01 -07:00
parent 13d8dfdc21
commit 5322a80ba4
2 changed files with 20 additions and 4 deletions

View File

@ -24,3 +24,6 @@ make V=1 all
$CXX $CXXFLAGS -std=c++11 -Isrc/ \
/src/magic_fuzzer.cc -o /out/magic_fuzzer \
-lfuzzer ./src/.libs/libmagic.a $FUZZER_LDFLAGS
cp ./magic/magic.mgc /out/

View File

@ -14,15 +14,28 @@
#include <stddef.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <magic.h>
struct Environment {
Environment() {
magic = magic_open(MAGIC_NONE);
if (magic_load(magic, "magic")) {
fprintf(stderr, "error loading magic file: %s\n", magic_error(magic));
exit(1);
}
}
magic_t magic;
};
static Environment env;
extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
if (size < 1)
return 0;
magic_t magic = magic_open(MAGIC_NONE);
magic_buffer(magic, data, size);
magic_close(magic);
magic_buffer(env.magic, data, size);
return 0;
}