diff options
author | Denys Vlasenko <vda.linux@googlemail.com> | 2011-10-20 13:21:55 +0200 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2011-10-20 13:21:55 +0200 |
commit | cd4d78f525526df0d2b62dce5a0dfc510debd6de (patch) | |
tree | 887a8d36e73fb8cca3b113a05436f28279165132 /networking/udhcp/dhcpc.c | |
parent | 1dff672335ce227c0875864e3819c8464f978c08 (diff) | |
download | busybox-w32-cd4d78f525526df0d2b62dce5a0dfc510debd6de.tar.gz busybox-w32-cd4d78f525526df0d2b62dce5a0dfc510debd6de.tar.bz2 busybox-w32-cd4d78f525526df0d2b62dce5a0dfc510debd6de.zip |
dhcpc: fix the case where we might add extra space at the end of envvar.
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'networking/udhcp/dhcpc.c')
-rw-r--r-- | networking/udhcp/dhcpc.c | 19 |
1 files changed, 10 insertions, 9 deletions
diff --git a/networking/udhcp/dhcpc.c b/networking/udhcp/dhcpc.c index d9269f277..d67769e65 100644 --- a/networking/udhcp/dhcpc.c +++ b/networking/udhcp/dhcpc.c | |||
@@ -173,16 +173,13 @@ static NOINLINE char *xmalloc_optname_optval(uint8_t *option, const struct dhcp_ | |||
173 | dest += sprintf(ret, "%s=", opt_name); | 173 | dest += sprintf(ret, "%s=", opt_name); |
174 | 174 | ||
175 | while (len >= optlen) { | 175 | while (len >= optlen) { |
176 | unsigned ip_ofs = 0; | ||
177 | |||
178 | switch (type) { | 176 | switch (type) { |
177 | case OPTION_IP: | ||
179 | case OPTION_IP_PAIR: | 178 | case OPTION_IP_PAIR: |
180 | dest += sprint_nip(dest, "", option); | 179 | dest += sprint_nip(dest, "", option); |
181 | *dest++ = '/'; | 180 | if (type == OPTION_IP) |
182 | ip_ofs = 4; | 181 | break; |
183 | /* fall through */ | 182 | dest += sprint_nip(dest, "/", option + 4); |
184 | case OPTION_IP: | ||
185 | dest += sprint_nip(dest, "", option + ip_ofs); | ||
186 | break; | 183 | break; |
187 | // case OPTION_BOOLEAN: | 184 | // case OPTION_BOOLEAN: |
188 | // dest += sprintf(dest, *option ? "yes" : "no"); | 185 | // dest += sprintf(dest, *option ? "yes" : "no"); |
@@ -204,10 +201,14 @@ static NOINLINE char *xmalloc_optname_optval(uint8_t *option, const struct dhcp_ | |||
204 | dest += sprintf(dest, type == OPTION_U32 ? "%lu" : "%ld", (unsigned long) ntohl(val_u32)); | 201 | dest += sprintf(dest, type == OPTION_U32 ? "%lu" : "%ld", (unsigned long) ntohl(val_u32)); |
205 | break; | 202 | break; |
206 | } | 203 | } |
204 | /* Note: options which use 'return' instead of 'break' | ||
205 | * (for example, OPTION_STRING) skip the code which handles | ||
206 | * the case of list of options. | ||
207 | */ | ||
207 | case OPTION_STRING: | 208 | case OPTION_STRING: |
208 | memcpy(dest, option, len); | 209 | memcpy(dest, option, len); |
209 | dest[len] = '\0'; | 210 | dest[len] = '\0'; |
210 | return ret; /* Short circuit this case */ | 211 | return ret; |
211 | case OPTION_STATIC_ROUTES: { | 212 | case OPTION_STATIC_ROUTES: { |
212 | /* Option binary format: | 213 | /* Option binary format: |
213 | * mask [one byte, 0..32] | 214 | * mask [one byte, 0..32] |
@@ -347,7 +348,7 @@ static NOINLINE char *xmalloc_optname_optval(uint8_t *option, const struct dhcp_ | |||
347 | // TODO: it can be a list only if (optflag->flags & OPTION_LIST). | 348 | // TODO: it can be a list only if (optflag->flags & OPTION_LIST). |
348 | // Should we bail out/warn if we see multi-ip option which is | 349 | // Should we bail out/warn if we see multi-ip option which is |
349 | // not allowed to be such (for example, DHCP_BROADCAST)? - | 350 | // not allowed to be such (for example, DHCP_BROADCAST)? - |
350 | if (len <= 0 /* || !(optflag->flags & OPTION_LIST) */) | 351 | if (len < optlen /* || !(optflag->flags & OPTION_LIST) */) |
351 | break; | 352 | break; |
352 | *dest++ = ' '; | 353 | *dest++ = ' '; |
353 | *dest = '\0'; | 354 | *dest = '\0'; |