mirror of https://github.com/google/oss-fuzz.git
libmagic needs magic file to work
This commit is contained in:
parent
13d8dfdc21
commit
5322a80ba4
|
@ -24,3 +24,6 @@ make V=1 all
|
||||||
$CXX $CXXFLAGS -std=c++11 -Isrc/ \
|
$CXX $CXXFLAGS -std=c++11 -Isrc/ \
|
||||||
/src/magic_fuzzer.cc -o /out/magic_fuzzer \
|
/src/magic_fuzzer.cc -o /out/magic_fuzzer \
|
||||||
-lfuzzer ./src/.libs/libmagic.a $FUZZER_LDFLAGS
|
-lfuzzer ./src/.libs/libmagic.a $FUZZER_LDFLAGS
|
||||||
|
|
||||||
|
cp ./magic/magic.mgc /out/
|
||||||
|
|
||||||
|
|
|
@ -14,15 +14,28 @@
|
||||||
|
|
||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
#include <magic.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) {
|
extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
|
||||||
if (size < 1)
|
if (size < 1)
|
||||||
return 0;
|
return 0;
|
||||||
|
magic_buffer(env.magic, data, size);
|
||||||
magic_t magic = magic_open(MAGIC_NONE);
|
|
||||||
magic_buffer(magic, data, size);
|
|
||||||
magic_close(magic);
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue