diff options
author | van Hauser <vh@thc.org> | 2019-07-14 20:04:26 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-07-14 20:04:26 +0200 |
commit | 054976c3903771e2267cfcf67f38fec3ced2ab77 (patch) | |
tree | 21e2f2e0bbe93341c3813d96576c5e83f62195d0 /afl-common.c | |
parent | 4a80dbdd10aedd3a3e70a0631aeb4e01438b634c (diff) | |
parent | da8e03e18a1d01cb4ea26fc8efb25c4e7708a0b5 (diff) | |
download | afl++-054976c3903771e2267cfcf67f38fec3ced2ab77.tar.gz |
Merge pull request #14 from vanhauser-thc/shared_memory_mmap_refactor
Shared memory mmap refactor
Diffstat (limited to 'afl-common.c')
-rw-r--r-- | afl-common.c | 69 |
1 files changed, 69 insertions, 0 deletions
diff --git a/afl-common.c b/afl-common.c new file mode 100644 index 00000000..1c5e5bfe --- /dev/null +++ b/afl-common.c @@ -0,0 +1,69 @@ +/* + gather some functions common to multiple executables + + detect_file_args + */ + +#include <stdlib.h> +#include <stdio.h> +#include <strings.h> + +#include "debug.h" +#include "alloc-inl.h" + +/* Detect @@ in args. */ +#ifndef __glibc__ +#include <unistd.h> +#endif +void detect_file_args(char** argv, u8* prog_in) { + + u32 i = 0; +#ifdef __GLIBC__ + u8* cwd = getcwd(NULL, 0); /* non portable glibc extension */ +#else + u8* cwd; + char *buf; + long size = pathconf(".", _PC_PATH_MAX); + if ((buf = (char *)malloc((size_t)size)) != NULL) { + cwd = getcwd(buf, (size_t)size); /* portable version */ + } else { + PFATAL("getcwd() failed"); + } +#endif + + if (!cwd) PFATAL("getcwd() failed"); + + while (argv[i]) { + + u8* aa_loc = strstr(argv[i], "@@"); + + if (aa_loc) { + + u8 *aa_subst, *n_arg; + + if (!prog_in) FATAL("@@ syntax is not supported by this tool."); + + /* Be sure that we're always using fully-qualified paths. */ + + if (prog_in[0] == '/') aa_subst = prog_in; + else aa_subst = alloc_printf("%s/%s", cwd, prog_in); + + /* Construct a replacement argv value. */ + + *aa_loc = 0; + n_arg = alloc_printf("%s%s%s", argv[i], aa_subst, aa_loc + 2); + argv[i] = n_arg; + *aa_loc = '@'; + + if (prog_in[0] != '/') ck_free(aa_subst); + + } + + i++; + + } + + free(cwd); /* not tracked */ + +} + |