external/busybox
リビジョン | 3ae2578282187c775247cb2c3cc9f442d9c138e0 (tree) |
---|---|
日時 | 2014-08-05 20:13:28 |
作者 | Tanguy Pruvot <tanguy.pruvot@gmai...> |
コミッター | Tanguy Pruvot |
android: clearenv should not set environ to NULL
Remove the old internal clearenv() function which is
no more required (exported in libc)
Change-Id: I357f6a3b057c366761b481c09b471d7c53d7a419
@@ -10,12 +10,22 @@ | ||
10 | 10 | #include <stdlib.h> |
11 | 11 | #include "libbb.h" |
12 | 12 | |
13 | -/* declared in stdlib.h */ | |
14 | -int clearenv() | |
13 | +#ifndef BIONIC_ICS | |
14 | +int clearenv(void) | |
15 | 15 | { |
16 | - environ = NULL; | |
16 | + char **P = environ; | |
17 | + | |
18 | + /* should never be NULL */ | |
19 | + if (!environ) | |
20 | + environ = (char **)xzalloc(sizeof(char *)); | |
21 | + | |
22 | + if (P != NULL) { | |
23 | + for (; *P; ++P) | |
24 | + *P = NULL; | |
25 | + } | |
17 | 26 | return 0; |
18 | 27 | } |
28 | +#endif | |
19 | 29 | |
20 | 30 | /* no /etc/shells anyway */ |
21 | 31 | char *getusershell() { return NULL; } |
@@ -322,6 +322,11 @@ char* FAST_FUNC xasprintf(const char *format, ...) | ||
322 | 322 | |
323 | 323 | void FAST_FUNC xsetenv(const char *key, const char *value) |
324 | 324 | { |
325 | +#ifdef __BIONIC__ | |
326 | + /* on login, can be NULL, and should not be for bionic */ | |
327 | + if (environ == NULL) | |
328 | + bb_error_msg_and_die("environment is not initialized"); | |
329 | +#endif | |
325 | 330 | if (setenv(key, value, 1)) |
326 | 331 | bb_error_msg_and_die("%s", bb_msg_memory_exhausted); |
327 | 332 | } |