tests: add sanitize_env() check

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
This commit is contained in:
Sami Kerola 2020-04-12 19:45:53 +01:00
parent 837f49c6bf
commit 3d6fa8da69
No known key found for this signature in database
GPG key ID: 0D46FEF7E61DBB46
2 changed files with 35 additions and 0 deletions

View file

@ -107,3 +107,34 @@ return secure_getenv(arg);
return getenv(arg);
#endif
}
#ifdef TEST_PROGRAM
int main(int argc, char **argv)
{
char *const *bad;
char copy[32];
char *p;
int retval = EXIT_SUCCESS;
for (bad = forbid; *bad; bad++) {
strcpy(copy, *bad);
p = strchr(copy, '=');
if (p)
*p = '\0';
setenv(copy, copy, 1);
}
sanitize_env();
for (bad = forbid; *bad; bad++) {
strcpy(copy, *bad);
p = strchr(copy, '=');
if (p)
*p = '\0';
p = getenv(copy);
if (p) {
warnx("%s was not removed", copy);
retval = EXIT_FAILURE;
}
}
return retval;
}
#endif