cgit

commit d96d2c98ebc4c2d3765f5b35c4142e0e828a421b

Author: Lukas Fleischer <cgit@cryptocrack.de>

shared.c: Only setenv() if value is non-null

Some setenv() implementations (e.g. the one in OpenBSD's stdlib)
segfault if we pass a NULL value. Only set environment variables if the
corresponding settings are defined to avoid this.

Note that this is a minor behaviour change as environment variables were
supposed to be set to an empty string if a setting was undefined. Given
that this feature isn't part of any official release yet, there's no
need to worry about backwards compatibility, really. Change the
documentation accordingly.

Signed-off-by: Lukas Fleischer <cgit@cryptocrack.de>

 cgitrc.5.txt | 2 +-
 shared.c | 2 +-


diff --git a/cgitrc.5.txt b/cgitrc.5.txt
index 4721c1e01335e10bd0fff7060b8281796a7ea557..a22423bcaeb9ebce08f73e1c219707511635dea7 100644
--- a/cgitrc.5.txt
+++ b/cgitrc.5.txt
@@ -500,7 +500,7 @@ - CGIT_REPO_CLONE_URL (from repo.clone-url)
 
 If a setting is not defined for a repository and the corresponding global
 setting is also not defined (if applicable), then the corresponding
-environment variable will be an empty string.
+environment variable will be unset.
 
 
 MACRO EXPANSION




diff --git a/shared.c b/shared.c
index 75c4b5c7e0c78b11bb7ff344e5ef0fd82fc9535d..0c8ce3e2ce79140192585b81d66a589dbaacbdbb 100644
--- a/shared.c
+++ b/shared.c
@@ -392,7 +392,7 @@
 	p = env_vars;
 	q = p + env_var_count;
 	for (; p < q; p++)
-		if (setenv(p->name, p->value, 1))
+		if (p->value && setenv(p->name, p->value, 1))
 			fprintf(stderr, warn, p->name, p->value);
 }