diff options
-rw-r--r-- | networking/udhcp/common.c | 30 |
1 files changed, 13 insertions, 17 deletions
diff --git a/networking/udhcp/common.c b/networking/udhcp/common.c index 9c27cd0ef..11b7b1f06 100644 --- a/networking/udhcp/common.c +++ b/networking/udhcp/common.c | |||
@@ -371,20 +371,23 @@ static NOINLINE void attach_option( | |||
371 | char *buffer, | 371 | char *buffer, |
372 | int length) | 372 | int length) |
373 | { | 373 | { |
374 | struct option_set *existing, *new, **curr; | 374 | struct option_set *existing; |
375 | char *allocated = NULL; | 375 | char *allocated; |
376 | 376 | ||
377 | existing = udhcp_find_option(*opt_list, optflag->code); | 377 | allocated = allocate_tempopt_if_needed(optflag, buffer, &length); |
378 | if (!existing) { | ||
379 | log2("Attaching option %02x to list", optflag->code); | ||
380 | allocated = allocate_tempopt_if_needed(optflag, buffer, &length); | ||
381 | #if ENABLE_FEATURE_UDHCP_RFC3397 | 378 | #if ENABLE_FEATURE_UDHCP_RFC3397 |
382 | if ((optflag->flags & OPTION_TYPE_MASK) == OPTION_DNS_STRING) { | 379 | if ((optflag->flags & OPTION_TYPE_MASK) == OPTION_DNS_STRING) { |
383 | /* reuse buffer and length for RFC1035-formatted string */ | 380 | /* reuse buffer and length for RFC1035-formatted string */ |
384 | allocated = buffer = (char *)dname_enc(NULL, 0, buffer, &length); | 381 | allocated = buffer = (char *)dname_enc(NULL, 0, buffer, &length); |
385 | } | 382 | } |
386 | #endif | 383 | #endif |
384 | |||
385 | existing = udhcp_find_option(*opt_list, optflag->code); | ||
386 | if (!existing) { | ||
387 | struct option_set *new, **curr; | ||
388 | |||
387 | /* make a new option */ | 389 | /* make a new option */ |
390 | log2("Attaching option %02x to list", optflag->code); | ||
388 | new = xmalloc(sizeof(*new)); | 391 | new = xmalloc(sizeof(*new)); |
389 | new->data = xmalloc(length + OPT_DATA); | 392 | new->data = xmalloc(length + OPT_DATA); |
390 | new->data[OPT_CODE] = optflag->code; | 393 | new->data[OPT_CODE] = optflag->code; |
@@ -405,14 +408,7 @@ static NOINLINE void attach_option( | |||
405 | 408 | ||
406 | /* add it to an existing option */ | 409 | /* add it to an existing option */ |
407 | log2("Attaching option %02x to existing member of list", optflag->code); | 410 | log2("Attaching option %02x to existing member of list", optflag->code); |
408 | allocated = allocate_tempopt_if_needed(optflag, buffer, &length); | ||
409 | old_len = existing->data[OPT_LEN]; | 411 | old_len = existing->data[OPT_LEN]; |
410 | #if ENABLE_FEATURE_UDHCP_RFC3397 | ||
411 | if ((optflag->flags & OPTION_TYPE_MASK) == OPTION_DNS_STRING) { | ||
412 | /* reuse buffer and length for RFC1035-formatted string */ | ||
413 | allocated = buffer = (char *)dname_enc(existing->data + OPT_DATA, old_len, buffer, &length); | ||
414 | } | ||
415 | #endif | ||
416 | if (old_len + length < 255) { | 412 | if (old_len + length < 255) { |
417 | /* actually 255 is ok too, but adding a space can overlow it */ | 413 | /* actually 255 is ok too, but adding a space can overlow it */ |
418 | 414 | ||