Don't allocate a new address buffer if we receive multiple responses
The current logic in the DNS resolution code allocates an address buffer based on the number of addresses in the response packet. If we receive multiple response packets in response to a single query packet, this means that we will reallocate a new buffer large enough for only the addresses in that specific packet, discarding any previous results in the process. Worse, we still keep track of the *total* number of addresses resolved in response to this query, not merely the number in the packet being currently processed. Use realloc() rather than malloc() to avoid overwriting the existing data, and allocate a buffer large enough for the total set of addresses rather than merely the number in this specific response.
This commit is contained in:
parent
e1b2b265af
commit
ec0051a569
1 changed files with 2 additions and 2 deletions
|
@ -276,8 +276,8 @@ recv_hook (grub_net_udp_socket_t sock __attribute__ ((unused)),
|
||||||
ptr++;
|
ptr++;
|
||||||
ptr += 4;
|
ptr += 4;
|
||||||
}
|
}
|
||||||
*data->addresses = grub_malloc (sizeof ((*data->addresses)[0])
|
*data->addresses = grub_realloc (*data->addresses, sizeof ((*data->addresses)[0])
|
||||||
* grub_be_to_cpu16 (head->ancount));
|
* (grub_be_to_cpu16 (head->ancount) + *data->naddresses));
|
||||||
if (!*data->addresses)
|
if (!*data->addresses)
|
||||||
{
|
{
|
||||||
grub_errno = GRUB_ERR_NONE;
|
grub_errno = GRUB_ERR_NONE;
|
||||||
|
|
Loading…
Reference in a new issue