Skip to content

Commit

Permalink
Fix memory leak in dhcpv6_add_server_cand in case odhcp6c_insert_stat…
Browse files Browse the repository at this point in the history
…e fails

If we fail to store information from the new server, the associated
NA and PD options will never be freed.  An attacker could use this
for denial-of-service.

Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
  • Loading branch information
bwhacks committed Jan 28, 2016
1 parent 7b22e48 commit b0d1c58
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/dhcpv6.c
Expand Up @@ -1362,6 +1362,7 @@ static void dhcpv6_handle_ia_status_code(const enum dhcpv6_msg orig,
}
}

// Note this always takes ownership of cand->ia_na and cand->ia_pd
static void dhcpv6_add_server_cand(const struct dhcpv6_server_cand *cand)
{
size_t cand_len, i;
Expand All @@ -1384,7 +1385,10 @@ static void dhcpv6_add_server_cand(const struct dhcpv6_server_cand *cand)
break;
}

odhcp6c_insert_state(STATE_SERVER_CAND, i * sizeof(*c), cand, sizeof(*cand));
if (odhcp6c_insert_state(STATE_SERVER_CAND, i * sizeof(*c), cand, sizeof(*cand))) {
free(cand->ia_na);
free(cand->ia_pd);
}
}

static void dhcpv6_clear_all_server_cand(void)
Expand Down

0 comments on commit b0d1c58

Please sign in to comment.