X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;f=compat%2Fsetenv.c;h=fc1439a6439393ff5224e98ab126607ceaa4994d;hb=b1bcfbe34439ff6d1a04d0bddb01eebe4df418a5;hp=b7d76785980b81a6f1057d678d34a732f45ca4cd;hpb=d69dc373cbf58d88d19dcbc6cff37e12b17f8fd2;p=git.git diff --git a/compat/setenv.c b/compat/setenv.c index b7d767859..fc1439a64 100644 --- a/compat/setenv.c +++ b/compat/setenv.c @@ -1,5 +1,4 @@ -#include -#include +#include "../git-compat-util.h" int gitsetenv(const char *name, const char *value, int replace) { @@ -7,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); @@ -17,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] = '=';