Skip to content

Commit

Permalink
Merge branch 'ef/setenv-putenv' into maint
Browse files Browse the repository at this point in the history
* ef/setenv-putenv:
  compat/setenv.c: error if name contains '='
  compat/setenv.c: update errno when erroring out
  • Loading branch information
Junio C Hamano committed Dec 28, 2011
2 parents 3c06ab6 + 6ac1b2a commit e8f6b51
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions compat/setenv.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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] = '=';
Expand Down

0 comments on commit e8f6b51

Please sign in to comment.