2
0
mirror of https://git.zx2c4.com/cgit/ synced 2024-11-10 07:10:33 +00:00

cgit.c: Do not restore unset environment variables

getenv() returns a NULL pointer if the specified variable name cannot be
found in the environment. However, some setenv() implementations crash
if a NULL pointer is passed as second argument. Only restore variables
that are not NULL.

See commit d96d2c98eb for a related patch.

Signed-off-by: Lukas Fleischer <cgit@cryptocrack.de>
This commit is contained in:
Lukas Fleischer 2013-04-10 12:30:52 +02:00 committed by Jason A. Donenfeld
parent 410da3ac1c
commit 8d8e84e72a

6
cgit.c
View File

@ -486,8 +486,10 @@ static int prepare_repo_cmd(struct cgit_context *ctx)
init_display_notes(NULL); init_display_notes(NULL);
/* We restore the unset variables afterward. */ /* We restore the unset variables afterward. */
setenv("HOME", user_home, 1); if (user_home)
setenv("XDG_CONFIG_HOME", xdg_home, 1); setenv("HOME", user_home, 1);
if (xdg_home)
setenv("XDG_CONFIG_HOME", xdg_home, 1);
if (nongit) { if (nongit) {
const char *name = ctx->repo->name; const char *name = ctx->repo->name;