aboutsummaryrefslogtreecommitdiff
path: root/networking
diff options
context:
space:
mode:
authorDenis Vlasenko <vda.linux@googlemail.com>2008-12-30 05:05:31 +0000
committerDenis Vlasenko <vda.linux@googlemail.com>2008-12-30 05:05:31 +0000
commit76ddc2e3e4837d0557fb6626394f87648e5f8c3b (patch)
treef545fe36c1ebc20c743ab28bc0df2b0f1d28b59d /networking
parentd6e8f9450cf055f0abfa424c5aa9e5a7c30d6593 (diff)
downloadbusybox-76ddc2e3e4837d0557fb6626394f87648e5f8c3b.tar.gz
libbb: add bb_unsetenv (taken from hush).
udhcpc: stop filtering environment passed to the script. crond: fix uncovered potential bug (failing unsetenv) mdev: fix uncovered potential bug (failing unsetenv) tcp, udpsvd: fix uncovered potential bug (failing unsetenv) function old new delta safe_setenv - 58 +58 bb_unsetenv - 55 +55 builtin_unset 139 138 -1 tcpudpsvd_main 1843 1830 -13 free_strings_and_unsetenv 87 53 -34 udhcp_run_script 1186 1133 -53 safe_setenv4 62 - -62 ------------------------------------------------------------------------------ (add/remove: 2/1 grow/shrink: 0/4 up/down: 113/-163) Total: -50 bytes
Diffstat (limited to 'networking')
-rw-r--r--networking/tcpudp.c3
-rw-r--r--networking/udhcp/script.c66
2 files changed, 32 insertions, 37 deletions
diff --git a/networking/tcpudp.c b/networking/tcpudp.c
index 3b73f213f..55a3e0899 100644
--- a/networking/tcpudp.c
+++ b/networking/tcpudp.c
@@ -85,8 +85,7 @@ static void undo_xsetenv(void)
char **pp = env_cur = &env_var[0];
while (*pp) {
char *var = *pp;
- *strchrnul(var, '=') = '\0';
- unsetenv(var);
+ bb_unsetenv(var);
free(var);
*pp++ = NULL;
}
diff --git a/networking/udhcp/script.c b/networking/udhcp/script.c
index 4ae17fb8d..5d42a45db 100644
--- a/networking/udhcp/script.c
+++ b/networking/udhcp/script.c
@@ -119,7 +119,8 @@ static char *alloc_fill_opts(uint8_t *option, const struct dhcp_option *type_p,
}
option += optlen;
len -= optlen;
- if (len <= 0) break;
+ if (len <= 0)
+ break;
dest += sprintf(dest, " ");
}
return ret;
@@ -130,9 +131,8 @@ static char *alloc_fill_opts(uint8_t *option, const struct dhcp_option *type_p,
static char **fill_envp(struct dhcpMessage *packet)
{
int num_options = 0;
- int i, j;
- char **envp;
- char *var;
+ int i;
+ char **envp, **curr;
const char *opt_name;
uint8_t *temp;
char over = 0;
@@ -156,21 +156,16 @@ static char **fill_envp(struct dhcpMessage *packet)
num_options++;
}
- envp = xzalloc(sizeof(char *) * (num_options + 5));
- j = 0;
- envp[j++] = xasprintf("interface=%s", client_config.interface);
- var = getenv("PATH");
- if (var)
- envp[j++] = xasprintf("PATH=%s", var);
- var = getenv("HOME");
- if (var)
- envp[j++] = xasprintf("HOME=%s", var);
+ curr = envp = xzalloc(sizeof(char *) * (num_options + 3));
+ *curr = xasprintf("interface=%s", client_config.interface);
+ putenv(*curr++);
if (packet == NULL)
return envp;
- envp[j] = xmalloc(sizeof("ip=255.255.255.255"));
- sprintip(envp[j++], "ip=", (uint8_t *) &packet->yiaddr);
+ *curr = xmalloc(sizeof("ip=255.255.255.255"));
+ sprintip(*curr, "ip=", (uint8_t *) &packet->yiaddr);
+ putenv(*curr++);
opt_name = dhcp_option_strings;
i = 0;
@@ -178,31 +173,36 @@ static char **fill_envp(struct dhcpMessage *packet)
temp = get_option(packet, dhcp_options[i].code);
if (!temp)
goto next;
- envp[j++] = alloc_fill_opts(temp, &dhcp_options[i], opt_name);
+ *curr = alloc_fill_opts(temp, &dhcp_options[i], opt_name);
+ putenv(*curr++);
/* Fill in a subnet bits option for things like /24 */
if (dhcp_options[i].code == DHCP_SUBNET) {
uint32_t subnet;
move_from_unaligned32(subnet, temp);
- envp[j++] = xasprintf("mask=%d", mton(subnet));
+ *curr = xasprintf("mask=%d", mton(subnet));
+ putenv(*curr++);
}
next:
opt_name += strlen(opt_name) + 1;
i++;
}
if (packet->siaddr) {
- envp[j] = xmalloc(sizeof("siaddr=255.255.255.255"));
- sprintip(envp[j++], "siaddr=", (uint8_t *) &packet->siaddr);
+ *curr = xmalloc(sizeof("siaddr=255.255.255.255"));
+ sprintip(*curr, "siaddr=", (uint8_t *) &packet->siaddr);
+ putenv(*curr++);
}
if (!(over & FILE_FIELD) && packet->file[0]) {
/* watch out for invalid packets */
packet->file[sizeof(packet->file) - 1] = '\0';
- envp[j++] = xasprintf("boot_file=%s", packet->file);
+ *curr = xasprintf("boot_file=%s", packet->file);
+ putenv(*curr++);
}
if (!(over & SNAME_FIELD) && packet->sname[0]) {
/* watch out for invalid packets */
packet->sname[sizeof(packet->sname) - 1] = '\0';
- envp[j++] = xasprintf("sname=%s", packet->sname);
+ *curr = xasprintf("sname=%s", packet->sname);
+ putenv(*curr++);
}
return envp;
}
@@ -211,29 +211,25 @@ static char **fill_envp(struct dhcpMessage *packet)
/* Call a script with a par file and env vars */
void FAST_FUNC udhcp_run_script(struct dhcpMessage *packet, const char *name)
{
- int pid;
char **envp, **curr;
+ char *argv[3];
if (client_config.script == NULL)
return;
- DEBUG("vfork'ing and execle'ing %s", client_config.script);
+ DEBUG("vfork'ing and exec'ing %s", client_config.script);
envp = fill_envp(packet);
/* call script */
-// can we use wait4pid(spawn(...)) here?
- pid = vfork();
- if (pid < 0) return;
- if (pid == 0) {
- /* close fd's? */
- /* exec script */
- execle(client_config.script, client_config.script,
- name, NULL, envp);
- bb_perror_msg_and_die("exec %s", client_config.script);
- }
- safe_waitpid(pid, NULL, 0);
- for (curr = envp; *curr; curr++)
+ argv[0] = (char*) client_config.script;
+ argv[1] = (char*) name;
+ argv[2] = NULL;
+ wait4pid(spawn(argv));
+
+ for (curr = envp; *curr; curr++) {
+ bb_unsetenv(*curr);
free(*curr);
+ }
free(envp);
}