mirror of
https://github.com/troglobit/finit.git
synced 2026-10-01 05:22:48 +07:00
test: fix use-after-free by switching to strdupa()
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
This commit is contained in:
@@ -1,2 +1,4 @@
|
||||
noinst_PROGRAMS = serv
|
||||
|
||||
serv_SOURCES = serv.c
|
||||
serv_CPPFLAGS = -D_XOPEN_SOURCE=600 -D_BSD_SOURCE -D_GNU_SOURCE -D_DEFAULT_SOURCE
|
||||
|
||||
+4
-12
@@ -21,29 +21,21 @@ static void verify_env(char *arg)
|
||||
char *replica;
|
||||
char *env;
|
||||
|
||||
key = replica = strdup(arg);
|
||||
key = replica = strdupa(arg);
|
||||
if (!replica)
|
||||
err(1, "Failed duplicating arg %s", arg);
|
||||
|
||||
value = strchr(replica, ':');
|
||||
if (!value) {
|
||||
free(replica);
|
||||
if (!value)
|
||||
errx(1, "Invalid format of KEY:VALUE arg, missing ':' in %s", replica);
|
||||
}
|
||||
*(value++) = 0;
|
||||
|
||||
env = getenv(key);
|
||||
if (!env) {
|
||||
free(replica);
|
||||
if (!env)
|
||||
errx(1, "No '%s' in environment", key);
|
||||
}
|
||||
|
||||
if (strcmp(env, value)) {
|
||||
free(replica);
|
||||
if (strcmp(env, value))
|
||||
errx(1, "Mismatch, environment '%s' vs expected value '%s'", env, value);
|
||||
}
|
||||
|
||||
free(replica);
|
||||
}
|
||||
|
||||
static void verify_noenv(char *key)
|
||||
|
||||
Reference in New Issue
Block a user