From: Rich Felker Date: Fri, 4 Oct 2013 19:49:55 +0000 (-0400) Subject: fix failure to check malloc result in setenv X-Git-Tag: v0.9.15~103 X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=543787039098c121917cb5f3e129d84b61afa61b;p=oweals%2Fmusl.git fix failure to check malloc result in setenv --- diff --git a/src/env/setenv.c b/src/env/setenv.c index c2c25444..0a458968 100644 --- a/src/env/setenv.c +++ b/src/env/setenv.c @@ -18,14 +18,14 @@ int setenv(const char *var, const char *value, int overwrite) l1 = strlen(var); l2 = strlen(value); s = malloc(l1+l2+2); - memcpy(s, var, l1); - s[l1] = '='; - memcpy(s+l1+1, value, l2); - s[l1+l2+1] = 0; - if (__putenv(s, 1)) { - free(s); - errno = ENOMEM; - return -1; + if (s) { + memcpy(s, var, l1); + s[l1] = '='; + memcpy(s+l1+1, value, l2); + s[l1+l2+1] = 0; + if (!__putenv(s, 1)) return 0; } - return 0; + free(s); + errno = ENOMEM; + return -1; }