diff options
author | Robert Swiecki <robert@swiecki.net> | 2018-11-20 15:59:25 +0100 |
---|---|---|
committer | Robert Swiecki <robert@swiecki.net> | 2018-11-20 15:59:25 +0100 |
commit | 15801e82dfb80bf5d551273f27d35198dd0ddfae (patch) | |
tree | 034e01227e8dae87aacf3a184eaa465620a3bb3b | |
parent | 8f2484395301747c65d87a5348b1bdc854895a65 (diff) | |
download | honggfuzz-15801e82dfb80bf5d551273f27d35198dd0ddfae.tar.gz |
cmdline: more work on envs
-rw-r--r-- | Makefile | 2 | ||||
-rw-r--r-- | cmdline.c | 33 | ||||
-rw-r--r-- | cmdline.h | 2 | ||||
-rw-r--r-- | sanitizers.c | 20 |
4 files changed, 32 insertions, 25 deletions
@@ -403,7 +403,7 @@ mangle.o: mangle.h honggfuzz.h libhfcommon/util.h input.h mangle.o: libhfcommon/common.h libhfcommon/log.h report.o: report.h honggfuzz.h libhfcommon/util.h libhfcommon/common.h report.o: libhfcommon/log.h -sanitizers.o: sanitizers.h honggfuzz.h libhfcommon/util.h +sanitizers.o: sanitizers.h honggfuzz.h libhfcommon/util.h cmdline.h sanitizers.o: libhfcommon/common.h libhfcommon/files.h libhfcommon/common.h sanitizers.o: libhfcommon/log.h socketfuzzer.o: honggfuzz.h libhfcommon/util.h libhfcommon/common.h @@ -31,6 +31,7 @@ #include <sched.h> #endif /* defined(_HF_ARCH_LINUX) */ #include <signal.h> +#include <stdint.h> #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -136,6 +137,29 @@ static void cmdlineUsage(const char* pname, struct custom_option* opts) { exit(0); } +bool cmdlineAddEnv(honggfuzz_t* hfuzz, char* env) { + size_t enveqlen = strlen(env); + const char* eqpos = strchr(env, '='); + if (eqpos) { + enveqlen = (uintptr_t)eqpos - (uintptr_t)env + 1; + } + + for (size_t i = 0; i < ARRAYSIZE(hfuzz->exe.envs); i++) { + if (hfuzz->exe.envs[i] == NULL) { + LOG_D("Adding envar '%s'", env); + hfuzz->exe.envs[i] = env; + return true; + } + if (strncmp(hfuzz->exe.envs[i], env, enveqlen) == 0) { + LOG_W("Replacing envar '%s' with '%s'", hfuzz->exe.envs[i], env); + hfuzz->exe.envs[i] = env; + return true; + } + } + LOG_E("No more space for new envars"); + return false; +} + rlim_t cmdlineParseRLimit(int res, const char* optarg, unsigned long mul) { struct rlimit cur; if (getrlimit(res, &cur) == -1) { @@ -269,7 +293,7 @@ bool cmdlineParse(int argc, char* argv[], honggfuzz_t* hfuzz) { .rssLimit = 0U, .dataLimit = 0U, .clearEnv = false, - .envs[0] = NULL, + .envs = {}, }, .timing = { @@ -637,11 +661,8 @@ bool cmdlineParse(int argc, char* argv[], honggfuzz_t* hfuzz) { #endif break; case 'E': - for (size_t i = 0; i < ARRAYSIZE(hfuzz->exe.envs); i++) { - if (hfuzz->exe.envs[i] == NULL) { - hfuzz->exe.envs[i] = optarg; - break; - } + if (!cmdlineAddEnv(hfuzz, optarg)) { + return false; } break; case 'w': @@ -30,6 +30,8 @@ rlim_t cmdlineParseRLimit(int res, const char* optarg, unsigned long mul); +bool cmdlineAddEnv(honggfuzz_t* hfuzz, char* env); + bool cmdlineParse(int argc, char* argv[], honggfuzz_t* hfuzz); #endif /* _HF_CMDLINE_H_ */ diff --git a/sanitizers.c b/sanitizers.c index 36310461..de0ab52f 100644 --- a/sanitizers.c +++ b/sanitizers.c @@ -10,6 +10,7 @@ #include <sys/stat.h> #include <sys/types.h> +#include "cmdline.h" #include "libhfcommon/common.h" #include "libhfcommon/files.h" #include "libhfcommon/log.h" @@ -110,18 +111,6 @@ static void sanitizers_AddFlag(honggfuzz_t* hfuzz, const char* env, char* buf, s LOG_W("The '%s' envar is already set. Not overriding it!", env); return; } - for (size_t i = 0; i < ARRAYSIZE(hfuzz->exe.envs); i++) { - if (hfuzz->exe.envs[i] == NULL) { - break; - } - char san_tmp[32]; - snprintf(san_tmp, sizeof(san_tmp), "%s=", env); - size_t l = strlen(san_tmp); - if (strncmp(hfuzz->exe.envs[i], san_tmp, l) == 0) { - LOG_D("The '%s' envar is set by user. Not overriding it!", env); - return; - } - } if (!hfuzz->sanitizer.enable) { snprintf(buf, buflen, "%s=%s", env, kSAN_REGULAR); @@ -138,12 +127,7 @@ static void sanitizers_AddFlag(honggfuzz_t* hfuzz, const char* env, char* buf, s util_ssnprintf(buf, buflen, ":soft_rss_limit_mb=%" PRId64, hfuzz->exe.rssLimit); } - for (size_t i = 0; i < ARRAYSIZE(hfuzz->exe.envs); i++) { - if (hfuzz->exe.envs[i] == NULL) { - hfuzz->exe.envs[i] = buf; - break; - } - } + cmdlineAddEnv(hfuzz, buf); LOG_D("%s", env); } |