Merge branch 'ef/setenv-putenv' into maint

* ef/setenv-putenv:
  compat/setenv.c: error if name contains '='
  compat/setenv.c: update errno when erroring out
This commit is contained in:
Junio C Hamano 2011-12-28 11:42:24 -08:00
commit e8f6b51a6b

View File

@ -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] = '=';