Skip to content

Commit

Permalink
Merge pull request googleprojectzero#132 from guyio/master
Browse files Browse the repository at this point in the history
removed code duplication of write_to_testcase
  • Loading branch information
ivanfratric authored Aug 16, 2018
2 parents 45adb6b + a3a1ec0 commit 39326f3
Showing 1 changed file with 6 additions and 33 deletions.
39 changes: 6 additions & 33 deletions afl-fuzz.c
Original file line number Diff line number Diff line change
Expand Up @@ -2728,39 +2728,12 @@ static void write_to_testcase(void* mem, u32 len) {
/* The same, but with an adjustable gap. Used for trimming. */

static void write_with_gap(char* mem, u32 len, u32 skip_at, u32 skip_len) {

s32 fd = out_fd;
u32 tail_len = len - skip_at - skip_len;

if (out_file) {

unlink(out_file); /* Ignore errors. */

fd = open(out_file, O_WRONLY | O_BINARY | O_CREAT | O_EXCL, 0600);

if (fd < 0) {
destroy_target_process(0);

unlink(out_file); /* Ignore errors. */

fd = open(out_file, O_WRONLY | O_BINARY | O_CREAT | O_EXCL, 0600);

if (fd < 0) PFATAL("Unable to create '%s'", out_file);
}

} else lseek(fd, 0, SEEK_SET);

if (skip_at) ck_write(fd, mem, skip_at, out_file);

if (tail_len) ck_write(fd, mem + skip_at + skip_len, tail_len, out_file);

if (!out_file) {

if (_chsize(fd, len - skip_len)) PFATAL("ftruncate() failed");
lseek(fd, 0, SEEK_SET);

} else close(fd);


char* trimmed_mem = malloc(len - skip_len);
memcpy(trimmed_mem, mem, skip_at); //copy start
memcpy(trimmed_mem + skip_at, mem + skip_at + skip_len, len - (skip_at + skip_len));
write_to_testcase(trimmed_mem, len - skip_len);
free(trimmed_mem);
}


Expand Down

0 comments on commit 39326f3

Please sign in to comment.