mirror of
git://git.musl-libc.org/musl
synced 2025-01-22 06:33:22 +00:00
fix failure to check malloc result in setenv
This commit is contained in:
parent
e5100b32d2
commit
5437870390
18
src/env/setenv.c
vendored
18
src/env/setenv.c
vendored
@ -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;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user