test: fix use-after-free by switching to strdupa()

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
This commit is contained in:
Joachim Wiberg
2022-05-30 06:53:37 +02:00
parent 96ff9c115c
commit 5ef669fb6c
2 changed files with 6 additions and 12 deletions
+2
View File
@@ -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
View File
@@ -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)