]> gitweb.ps.run Git - ps-cgit/commitdiff
cgit.c: Do not restore unset environment variables
authorLukas Fleischer <cgit@cryptocrack.de>
Wed, 10 Apr 2013 10:30:52 +0000 (12:30 +0200)
committerJason A. Donenfeld <Jason@zx2c4.com>
Wed, 10 Apr 2013 11:46:30 +0000 (13:46 +0200)
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>
cgit.c

diff --git a/cgit.c b/cgit.c
index 0bf8972397608506b978d0c2dc275185a66c88b4..4dadd97e3d7dbfda597771f26d7e9b4c510c463f 100644 (file)
--- a/cgit.c
+++ b/cgit.c
@@ -486,8 +486,10 @@ static int prepare_repo_cmd(struct cgit_context *ctx)
        init_display_notes(NULL);
 
        /* We restore the unset variables afterward. */
-       setenv("HOME", user_home, 1);
-       setenv("XDG_CONFIG_HOME", xdg_home, 1);
+       if (user_home)
+               setenv("HOME", user_home, 1);
+       if (xdg_home)
+               setenv("XDG_CONFIG_HOME", xdg_home, 1);
 
        if (nongit) {
                const char *name = ctx->repo->name;