projects
/
oweals
/
musl.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
| inline |
side by side
(parent:
e5100b3
)
fix failure to check malloc result in setenv
author
Rich Felker
<dalias@aerifal.cx>
Fri, 4 Oct 2013 19:49:55 +0000
(15:49 -0400)
committer
Rich Felker
<dalias@aerifal.cx>
Fri, 4 Oct 2013 19:49:55 +0000
(15:49 -0400)
src/env/setenv.c
patch
|
blob
|
history
diff --git
a/src/env/setenv.c
b/src/env/setenv.c
index c2c25444cbbd069c1eb99cd9f9ec8a57be0d18ce..0a458968669a6280f070271a80a6069af9152b43 100644
(file)
--- 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;
}