From ba39dd3374e8fb934cfbae2a26d6d5adc95fc26b Mon Sep 17 00:00:00 2001 From: pancake Date: Mon, 24 Aug 2015 13:00:54 +0200 Subject: [PATCH] Add regression test for the map crash --- regress/Makefile | 11 +++++++++++ regress/map_crash.c | 29 +++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+) create mode 100644 regress/Makefile create mode 100644 regress/map_crash.c diff --git a/regress/Makefile b/regress/Makefile new file mode 100644 index 00000000..159489d0 --- /dev/null +++ b/regress/Makefile @@ -0,0 +1,11 @@ +CFLAGS+=-I../include +LDFLAGS=-L.. -lunicorn + +TESTS=map_crash map_regs + +all: $(TESTS) + +clean: + rm -f $(TESTS) + +.PHONY: all clean diff --git a/regress/map_crash.c b/regress/map_crash.c new file mode 100644 index 00000000..e7bc78a7 --- /dev/null +++ b/regress/map_crash.c @@ -0,0 +1,29 @@ +#include +#include +#include +#include + +#define UC_BUG_WRITE_SIZE 13000 +#define UC_BUG_WRITE_ADDR 0x1000 + +int main() { + int size; + uint8_t *buf; + uch uh; + uc_err err = uc_open (UC_ARCH_X86, UC_MODE_64, &uh); + if (err) { + fprintf (stderr, "Cannot initialize unicorn\n"); + return 1; + } + size = UC_BUG_WRITE_SIZE; + buf = malloc (size); + if (!buf) { + fprintf (stderr, "Cannot allocate\n"); + return 1; + } + memset (buf, 0, size); + uc_mem_map (uh, UC_BUG_WRITE_ADDR, size); + uc_mem_write (uh, UC_BUG_WRITE_ADDR, buf, size); + uc_close (&uh); + return 0; +}