Add libfuzzer target to fuzz/x86_instruction_emulator

This target enables integration into oss-fuzz. Changing invalid input return
to -1 as values other then 0/-1 are reserved by libfuzzer. Also adding the
missing __wrap_vsnprintf wrapper which is required for successful oss-fuzz
build.

Signed-off-by: Tamas K Lengyel <tamas@tklengyel.com>
Acked-by: Jan Beulich <jbeulich@suse.com>
This commit is contained in:
Tamas K Lengyel authored and Jan Beulich committed 2024-07-23 13:58:07 +02:00
1 parent c4bdb14b80
commit b518013ca1
3 files changed
+18 -5

No files matched your search

+5 -1
View File
@@ -58,6 +58,9 @@ afl-harness: afl-harness.o $(OBJS) cpuid.o wrappers.o
afl-harness-cov: afl-harness-cov.o $(patsubst %.o,%-cov.o,$(OBJS)) cpuid.o wrappers.o afl-harness-cov: afl-harness-cov.o $(patsubst %.o,%-cov.o,$(OBJS)) cpuid.o wrappers.o
$(CC) $(CFLAGS) $(GCOV_FLAGS) $(addprefix -Wl$(comma)--wrap=,$(WRAPPED)) $^ -o $@ $(CC) $(CFLAGS) $(GCOV_FLAGS) $(addprefix -Wl$(comma)--wrap=,$(WRAPPED)) $^ -o $@
libfuzzer-harness: $(OBJS) cpuid.o wrappers.o
$(CC) $(CFLAGS) $(LIB_FUZZING_ENGINE) -fsanitize=fuzzer $(addprefix -Wl$(comma)--wrap=,$(WRAPPED)) $^ -o $@
# Common targets # Common targets
.PHONY: all .PHONY: all
all: x86-insn-fuzz-all all: x86-insn-fuzz-all
@@ -67,7 +70,8 @@ distclean: clean
.PHONY: clean .PHONY: clean
clean: clean:
rm -f *.a *.o $(DEPS_RM) afl-harness afl-harness-cov *.gcda *.gcno *.gcov rm -f *.a *.o $(DEPS_RM) *.gcda *.gcno *.gcov
rm -f afl-harness afl-harness-cov libfuzzer-harness
rm -rf x86_emulate x86-emulate.c x86-emulate.h wrappers.c cpuid.c rm -rf x86_emulate x86-emulate.c x86-emulate.h wrappers.c cpuid.c
.PHONY: install .PHONY: install
@@ -906,14 +906,12 @@ int LLVMFuzzerTestOneInput(const uint8_t *data_p, size_t size)
if ( size <= DATA_OFFSET ) if ( size <= DATA_OFFSET )
{ {
printf("Input too small\n"); return -1;
return 1;
} }
if ( size > FUZZ_CORPUS_SIZE ) if ( size > FUZZ_CORPUS_SIZE )
{ {
printf("Input too large\n"); return -1;
return 1;
} }
memcpy(&input, data_p, size); memcpy(&input, data_p, size);
+11
View File
@@ -91,6 +91,17 @@ int __wrap_snprintf(char *buf, size_t n, const char *fmt, ...)
return rc; return rc;
} }
int __wrap_vsnprintf(char *buf, size_t n, const char *fmt, va_list varg)
{
int rc;
emul_save_fpu_state();
rc = __real_vsnprintf(buf, n, fmt, varg);
emul_restore_fpu_state();
return rc;
}
char *__wrap_strstr(const char *s1, const char *s2) char *__wrap_strstr(const char *s1, const char *s2)
{ {
char *s; char *s;
Reference in new issue
Block a user
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.