From 57590c72b4d3b02e32732c7d79514c0281d6c2b5 Mon Sep 17 00:00:00 2001 From: Erik Faye-Lund Date: Wed, 14 Dec 2011 15:07:08 +0100 Subject: compat/setenv.c: update errno when erroring out Previously, gitsetenv didn't update errno as it should when erroring out. Fix this. Signed-off-by: Erik Faye-Lund Signed-off-by: Junio C Hamano --- compat/setenv.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/compat/setenv.c b/compat/setenv.c index 3a22ea7b75..89947b7134 100644 --- a/compat/setenv.c +++ b/compat/setenv.c @@ -6,7 +6,10 @@ int gitsetenv(const char *name, const char *value, int replace) size_t namelen, valuelen; char *envstr; - if (!name || !value) return -1; + if (!name || !value) { + errno = EINVAL; + return -1; + } if (!replace) { char *oldval = NULL; oldval = getenv(name); @@ -16,7 +19,10 @@ int gitsetenv(const char *name, const char *value, int replace) namelen = strlen(name); valuelen = strlen(value); envstr = malloc((namelen + valuelen + 2)); - if (!envstr) return -1; + if (!envstr) { + errno = ENOMEM; + return -1; + } memcpy(envstr, name, namelen); envstr[namelen] = '='; -- cgit v1.2.3 From 6ac1b2a3b8bd970e9fc175c42927f00d4d465bbf Mon Sep 17 00:00:00 2001 From: Erik Faye-Lund Date: Wed, 14 Dec 2011 15:07:09 +0100 Subject: compat/setenv.c: error if name contains '=' According to POSIX, setenv should error out with EINVAL if it's asked to set an environment variable whose name contains an equals sign. Implement this detail in our compatibility-fallback. Signed-off-by: Erik Faye-Lund Signed-off-by: Junio C Hamano --- compat/setenv.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compat/setenv.c b/compat/setenv.c index 89947b7134..fc1439a643 100644 --- a/compat/setenv.c +++ b/compat/setenv.c @@ -6,7 +6,7 @@ int gitsetenv(const char *name, const char *value, int replace) size_t namelen, valuelen; char *envstr; - if (!name || !value) { + if (!name || strchr(name, '=') || !value) { errno = EINVAL; return -1; } -- cgit v1.2.3