net: avoid closing NULL socket in DNS lookup
Refactor code so that we do not store NULL pointers in array of in-flight DNS servers. Reported-By: Josef Bacik <jbacik@fb.com>
This commit is contained in:
parent
76197d9be6
commit
a01ab69848
1 changed files with 7 additions and 9 deletions
|
@ -437,7 +437,7 @@ grub_net_dns_lookup (const char *name,
|
|||
struct recv_data data = {naddresses, addresses, cache,
|
||||
grub_cpu_to_be16 (id++), 0, 0, name, 0};
|
||||
grub_uint8_t *nbd;
|
||||
int have_server = 0;
|
||||
grub_size_t try_server = 0;
|
||||
|
||||
if (!servers)
|
||||
{
|
||||
|
@ -543,33 +543,31 @@ grub_net_dns_lookup (const char *name,
|
|||
for (i = 0; i < n_servers * 4; i++)
|
||||
{
|
||||
/* Connect to a next server. */
|
||||
while (!(i & 1) && send_servers < n_servers)
|
||||
while (!(i & 1) && try_server < n_servers)
|
||||
{
|
||||
sockets[send_servers] = grub_net_udp_open (servers[send_servers],
|
||||
sockets[send_servers] = grub_net_udp_open (servers[try_server++],
|
||||
DNS_PORT,
|
||||
recv_hook,
|
||||
&data);
|
||||
send_servers++;
|
||||
if (!sockets[send_servers - 1])
|
||||
if (!sockets[send_servers])
|
||||
{
|
||||
err = grub_errno;
|
||||
grub_errno = GRUB_ERR_NONE;
|
||||
}
|
||||
else
|
||||
{
|
||||
have_server = 1;
|
||||
send_servers++;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!have_server)
|
||||
if (!send_servers)
|
||||
goto out;
|
||||
if (*data.naddresses)
|
||||
goto out;
|
||||
for (j = 0; j < send_servers; j++)
|
||||
{
|
||||
grub_err_t err2;
|
||||
if (!sockets[j])
|
||||
continue;
|
||||
|
||||
nb->data = nbd;
|
||||
|
||||
grub_size_t t = 0;
|
||||
|
|
Loading…
Reference in a new issue