diff options
Diffstat (limited to 'compat/setenv.c')
-rw-r--r-- | compat/setenv.c | 12 |
1 files changed, 9 insertions, 3 deletions
diff --git a/compat/setenv.c b/compat/setenv.c index 3a22ea7b75..7849f258d2 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); @@ -15,8 +18,11 @@ 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; + envstr = malloc(st_add3(namelen, valuelen, 2)); + if (!envstr) { + errno = ENOMEM; + return -1; + } memcpy(envstr, name, namelen); envstr[namelen] = '='; |