提交 54378703 编写于 作者: R Rich Felker

fix failure to check malloc result in setenv

上级 e5100b32
...@@ -18,14 +18,14 @@ int setenv(const char *var, const char *value, int overwrite) ...@@ -18,14 +18,14 @@ int setenv(const char *var, const char *value, int overwrite)
l1 = strlen(var); l1 = strlen(var);
l2 = strlen(value); l2 = strlen(value);
s = malloc(l1+l2+2); s = malloc(l1+l2+2);
memcpy(s, var, l1); if (s) {
s[l1] = '='; memcpy(s, var, l1);
memcpy(s+l1+1, value, l2); s[l1] = '=';
s[l1+l2+1] = 0; memcpy(s+l1+1, value, l2);
if (__putenv(s, 1)) { s[l1+l2+1] = 0;
free(s); if (!__putenv(s, 1)) return 0;
errno = ENOMEM;
return -1;
} }
return 0; free(s);
errno = ENOMEM;
return -1;
} }
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册