diff options
author | Lukas Fleischer | 2013-04-10 12:30:52 +0200 |
---|---|---|
committer | Jason A. Donenfeld | 2013-04-10 13:46:30 +0200 |
commit | 8d8e84e72a24f474a6659ca04d0906723b2ac975 (patch) | |
tree | 60942d045a435c87284da5a21df7be407e7c7978 | |
parent | 410da3ac1cdb002116c08f143ce82534897ede27 (diff) | |
download | cgit-8d8e84e72a24f474a6659ca04d0906723b2ac975.tar.gz cgit-8d8e84e72a24f474a6659ca04d0906723b2ac975.tar.bz2 cgit-8d8e84e72a24f474a6659ca04d0906723b2ac975.zip |
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 d96d2c98ebc4c2d3765f5b35c4142e0e828a421b for a related patch.
Signed-off-by: Lukas Fleischer <cgit@cryptocrack.de>
-rw-r--r-- | cgit.c | 6 |
1 files changed, 4 insertions, 2 deletions
@@ -486,8 +486,10 @@ static int prepare_repo_cmd(struct cgit_context *ctx) | |||
486 | init_display_notes(NULL); | 486 | init_display_notes(NULL); |
487 | 487 | ||
488 | /* We restore the unset variables afterward. */ | 488 | /* We restore the unset variables afterward. */ |
489 | setenv("HOME", user_home, 1); | 489 | if (user_home) |
490 | setenv("XDG_CONFIG_HOME", xdg_home, 1); | 490 | setenv("HOME", user_home, 1); |
491 | if (xdg_home) | ||
492 | setenv("XDG_CONFIG_HOME", xdg_home, 1); | ||
491 | 493 | ||
492 | if (nongit) { | 494 | if (nongit) { |
493 | const char *name = ctx->repo->name; | 495 | const char *name = ctx->repo->name; |