mirror of
https://github.com/AFLplusplus/AFLplusplus.git
synced 2025-06-10 09:11:34 +00:00
suggested env vars for lazy ppl
This commit is contained in:
parent
17211253b2
commit
89cf94f0e6
@ -39,6 +39,7 @@
|
||||
#define STRINGIFY_VAL_SIZE_MAX (16)
|
||||
|
||||
void detect_file_args(char **argv, u8 *prog_in, bool *use_stdin);
|
||||
void print_suggested_envs(char *mispelled_env);
|
||||
void check_environment_vars(char **env);
|
||||
|
||||
char **argv_cpy_dup(int argc, char **argv);
|
||||
|
@ -3917,6 +3917,7 @@ static void internal_malloc_stats(mstate m) {
|
||||
\
|
||||
} else if (RTCHECK(B == smallbin_at(M, I) || \
|
||||
\
|
||||
\
|
||||
(ok_address(M, B) && B->fd == P))) { \
|
||||
\
|
||||
F->bk = B; \
|
||||
@ -4128,6 +4129,7 @@ static void internal_malloc_stats(mstate m) {
|
||||
\
|
||||
} else \
|
||||
\
|
||||
\
|
||||
CORRUPTION_ERROR_ACTION(M); \
|
||||
if (R != 0) { \
|
||||
\
|
||||
@ -4144,6 +4146,7 @@ static void internal_malloc_stats(mstate m) {
|
||||
\
|
||||
} else \
|
||||
\
|
||||
\
|
||||
CORRUPTION_ERROR_ACTION(M); \
|
||||
\
|
||||
} \
|
||||
@ -4156,12 +4159,14 @@ static void internal_malloc_stats(mstate m) {
|
||||
\
|
||||
} else \
|
||||
\
|
||||
\
|
||||
CORRUPTION_ERROR_ACTION(M); \
|
||||
\
|
||||
} \
|
||||
\
|
||||
} else \
|
||||
\
|
||||
\
|
||||
CORRUPTION_ERROR_ACTION(M); \
|
||||
\
|
||||
} \
|
||||
|
116
src/afl-common.c
116
src/afl-common.c
@ -518,6 +518,120 @@ int parse_afl_kill_signal_env(u8 *afl_kill_signal_env, int default_signal) {
|
||||
|
||||
}
|
||||
|
||||
#define HELPER_MIN3(a, b, c) \
|
||||
((a) < (b) ? ((a) < (c) ? (a) : (c)) : ((b) < (c) ? (b) : (c)))
|
||||
|
||||
// from
|
||||
// https://en.wikibooks.org/wiki/Algorithm_Implementation/Strings/Levenshtein_distance#C
|
||||
static int string_distance_levenshtein(char *s1, char *s2) {
|
||||
|
||||
unsigned int s1len, s2len, x, y, lastdiag, olddiag;
|
||||
s1len = strlen(s1);
|
||||
s2len = strlen(s2);
|
||||
unsigned int column[s1len + 1];
|
||||
for (y = 1; y <= s1len; y++)
|
||||
column[y] = y;
|
||||
for (x = 1; x <= s2len; x++) {
|
||||
|
||||
column[0] = x;
|
||||
for (y = 1, lastdiag = x - 1; y <= s1len; y++) {
|
||||
|
||||
olddiag = column[y];
|
||||
column[y] = HELPER_MIN3(column[y] + 1, column[y - 1] + 1,
|
||||
lastdiag + (s1[y - 1] == s2[x - 1] ? 0 : 1));
|
||||
lastdiag = olddiag;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return column[s1len];
|
||||
|
||||
}
|
||||
|
||||
#undef HELPER_MIN3
|
||||
|
||||
void print_suggested_envs(char *mispelled_env) {
|
||||
|
||||
size_t env_name_len =
|
||||
strcspn(mispelled_env, "=") - 4; // remove the AFL_prefix
|
||||
char *env_name = ck_alloc(env_name_len + 1);
|
||||
memcpy(env_name, mispelled_env + 4, env_name_len);
|
||||
|
||||
char *seen = ck_alloc(sizeof(afl_environment_variables) / sizeof(char *));
|
||||
|
||||
int j;
|
||||
for (j = 0; afl_environment_variables[j] != NULL; ++j) {
|
||||
|
||||
char *afl_env = afl_environment_variables[j] + 4;
|
||||
|
||||
int distance = string_distance_levenshtein(afl_env, env_name);
|
||||
if (distance <= 3 && seen[j] == 0) {
|
||||
|
||||
SAYF("Did you mean %s?\n", afl_environment_variables[j]);
|
||||
seen[j] = 1;
|
||||
|
||||
}
|
||||
|
||||
size_t afl_env_len = strlen(afl_env);
|
||||
char * reduced = ck_alloc(afl_env_len + 1);
|
||||
|
||||
size_t start = 0;
|
||||
while (start < afl_env_len) {
|
||||
|
||||
size_t end = start + strcspn(afl_env + start, "_") + 1;
|
||||
memcpy(reduced, afl_env, start);
|
||||
if (end < afl_env_len)
|
||||
memcpy(reduced + start, afl_env + end, afl_env_len - end);
|
||||
reduced[afl_env_len - end + start] = 0;
|
||||
|
||||
int distance = string_distance_levenshtein(reduced, env_name);
|
||||
if (distance <= 3 && seen[j] == 0) {
|
||||
|
||||
SAYF("Did you mean %s?\n", afl_environment_variables[j]);
|
||||
seen[j] = 1;
|
||||
|
||||
}
|
||||
|
||||
start = end;
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
char * reduced = ck_alloc(env_name_len + 1);
|
||||
size_t start = 0;
|
||||
while (start < env_name_len) {
|
||||
|
||||
size_t end = start + strcspn(env_name + start, "_") + 1;
|
||||
memcpy(reduced, env_name, start);
|
||||
if (end < env_name_len)
|
||||
memcpy(reduced + start, env_name + end, env_name_len - end);
|
||||
reduced[env_name_len - end + start] = 0;
|
||||
|
||||
for (j = 0; afl_environment_variables[j] != NULL; ++j) {
|
||||
|
||||
int distance = string_distance_levenshtein(
|
||||
afl_environment_variables[j] + 4, reduced);
|
||||
if (distance <= 3 && seen[j] == 0) {
|
||||
|
||||
SAYF("Did you mean %s?\n", afl_environment_variables[j]);
|
||||
seen[j] = 1;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
start = end;
|
||||
|
||||
};
|
||||
|
||||
ck_free(env_name);
|
||||
ck_free(reduced);
|
||||
ck_free(seen);
|
||||
|
||||
}
|
||||
|
||||
void check_environment_vars(char **envp) {
|
||||
|
||||
if (be_quiet) { return; }
|
||||
@ -587,6 +701,8 @@ void check_environment_vars(char **envp) {
|
||||
WARNF("Mistyped AFL environment variable: %s", env);
|
||||
issue_detected = 1;
|
||||
|
||||
print_suggested_envs(env);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -486,6 +486,8 @@ void read_afl_environment(afl_state_t *afl, char **envp) {
|
||||
WARNF("Mistyped AFL environment variable: %s", env);
|
||||
issue_detected = 1;
|
||||
|
||||
print_suggested_envs(env);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user