summaryrefslogtreecommitdiff
path: root/compat
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2011-12-22 19:27:24 (GMT)
committerJunio C Hamano <gitster@pobox.com>2011-12-22 19:27:24 (GMT)
commit340c54ae5531ab08022c77cf4a12beb2c420bc24 (patch)
tree29fd11581603b5bd43e90956ace4bb767cfebf51 /compat
parentded408fd20e2fedb76850c9fa9bbaa26b888aa7c (diff)
parent6ac1b2a3b8bd970e9fc175c42927f00d4d465bbf (diff)
downloadgit-340c54ae5531ab08022c77cf4a12beb2c420bc24.zip
git-340c54ae5531ab08022c77cf4a12beb2c420bc24.tar.gz
git-340c54ae5531ab08022c77cf4a12beb2c420bc24.tar.bz2
Merge branch 'ef/setenv-putenv'
* ef/setenv-putenv: compat/setenv.c: error if name contains '=' compat/setenv.c: update errno when erroring out
Diffstat (limited to 'compat')
-rw-r--r--compat/setenv.c10
1 files changed, 8 insertions, 2 deletions
diff --git a/compat/setenv.c b/compat/setenv.c
index 3a22ea7..fc1439a 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 || strchr(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] = '=';