mirror of
https://git.savannah.gnu.org/git/grub.git
synced 2026-10-29 02:31:05 +00:00
net/dns: Simplify error handling of recv_hook() function
Signed-off-by: Renaud Métrich <rmetrich@redhat.com> Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
This commit is contained in:
1 parent
f301a9356b
commit
6c0edcdc27
1 file changed
+15
-33
+15
-33
@@ -262,42 +262,26 @@ recv_hook (grub_net_udp_socket_t sock __attribute__ ((unused)),
|
|||||||
We may get multiple responses due to network condition, so check here
|
We may get multiple responses due to network condition, so check here
|
||||||
and quit early. */
|
and quit early. */
|
||||||
if (*data->addresses)
|
if (*data->addresses)
|
||||||
{
|
goto out;
|
||||||
grub_netbuff_free (nb);
|
|
||||||
return GRUB_ERR_NONE;
|
|
||||||
}
|
|
||||||
|
|
||||||
head = (struct dns_header *) nb->data;
|
head = (struct dns_header *) nb->data;
|
||||||
ptr = (grub_uint8_t *) (head + 1);
|
ptr = (grub_uint8_t *) (head + 1);
|
||||||
if (ptr >= nb->tail)
|
if (ptr >= nb->tail)
|
||||||
{
|
goto out;
|
||||||
grub_netbuff_free (nb);
|
|
||||||
return GRUB_ERR_NONE;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (head->id != data->id)
|
if (head->id != data->id)
|
||||||
{
|
goto out;
|
||||||
grub_netbuff_free (nb);
|
|
||||||
return GRUB_ERR_NONE;
|
|
||||||
}
|
|
||||||
if (!(head->flags & FLAGS_RESPONSE) || (head->flags & FLAGS_OPCODE))
|
if (!(head->flags & FLAGS_RESPONSE) || (head->flags & FLAGS_OPCODE))
|
||||||
{
|
goto out;
|
||||||
grub_netbuff_free (nb);
|
|
||||||
return GRUB_ERR_NONE;
|
|
||||||
}
|
|
||||||
if (head->ra_z_r_code & ERRCODE_MASK)
|
if (head->ra_z_r_code & ERRCODE_MASK)
|
||||||
{
|
{
|
||||||
data->dns_err = 1;
|
data->dns_err = 1;
|
||||||
grub_netbuff_free (nb);
|
goto out;
|
||||||
return GRUB_ERR_NONE;
|
|
||||||
}
|
}
|
||||||
for (i = 0; i < grub_be_to_cpu16 (head->qdcount); i++)
|
for (i = 0; i < grub_be_to_cpu16 (head->qdcount); i++)
|
||||||
{
|
{
|
||||||
if (ptr >= nb->tail)
|
if (ptr >= nb->tail)
|
||||||
{
|
goto out;
|
||||||
grub_netbuff_free (nb);
|
|
||||||
return GRUB_ERR_NONE;
|
|
||||||
}
|
|
||||||
while (ptr < nb->tail && !((*ptr & 0xc0) || *ptr == 0))
|
while (ptr < nb->tail && !((*ptr & 0xc0) || *ptr == 0))
|
||||||
ptr += *ptr + 1;
|
ptr += *ptr + 1;
|
||||||
if (ptr < nb->tail && (*ptr & 0xc0))
|
if (ptr < nb->tail && (*ptr & 0xc0))
|
||||||
@@ -310,8 +294,7 @@ recv_hook (grub_net_udp_socket_t sock __attribute__ ((unused)),
|
|||||||
if (!*data->addresses)
|
if (!*data->addresses)
|
||||||
{
|
{
|
||||||
grub_errno = GRUB_ERR_NONE;
|
grub_errno = GRUB_ERR_NONE;
|
||||||
grub_netbuff_free (nb);
|
goto out;
|
||||||
return GRUB_ERR_NONE;
|
|
||||||
}
|
}
|
||||||
reparse_ptr = ptr;
|
reparse_ptr = ptr;
|
||||||
reparse:
|
reparse:
|
||||||
@@ -325,7 +308,7 @@ recv_hook (grub_net_udp_socket_t sock __attribute__ ((unused)),
|
|||||||
{
|
{
|
||||||
if (!*data->naddresses)
|
if (!*data->naddresses)
|
||||||
grub_free (*data->addresses);
|
grub_free (*data->addresses);
|
||||||
return GRUB_ERR_NONE;
|
goto out;
|
||||||
}
|
}
|
||||||
ignored = !check_name (ptr, nb->data, nb->tail, data->name);
|
ignored = !check_name (ptr, nb->data, nb->tail, data->name);
|
||||||
while (ptr < nb->tail && !((*ptr & 0xc0) || *ptr == 0))
|
while (ptr < nb->tail && !((*ptr & 0xc0) || *ptr == 0))
|
||||||
@@ -337,8 +320,7 @@ recv_hook (grub_net_udp_socket_t sock __attribute__ ((unused)),
|
|||||||
{
|
{
|
||||||
if (!*data->naddresses)
|
if (!*data->naddresses)
|
||||||
grub_free (*data->addresses);
|
grub_free (*data->addresses);
|
||||||
grub_netbuff_free (nb);
|
goto out;
|
||||||
return GRUB_ERR_NONE;
|
|
||||||
}
|
}
|
||||||
if (*ptr++ != 0)
|
if (*ptr++ != 0)
|
||||||
ignored = 1;
|
ignored = 1;
|
||||||
@@ -358,8 +340,7 @@ recv_hook (grub_net_udp_socket_t sock __attribute__ ((unused)),
|
|||||||
{
|
{
|
||||||
if (!*data->naddresses)
|
if (!*data->naddresses)
|
||||||
grub_free (*data->addresses);
|
grub_free (*data->addresses);
|
||||||
grub_netbuff_free (nb);
|
goto out;
|
||||||
return GRUB_ERR_NONE;
|
|
||||||
}
|
}
|
||||||
if (!ignored)
|
if (!ignored)
|
||||||
{
|
{
|
||||||
@@ -400,15 +381,14 @@ recv_hook (grub_net_udp_socket_t sock __attribute__ ((unused)),
|
|||||||
if (!data->name)
|
if (!data->name)
|
||||||
{
|
{
|
||||||
data->dns_err = 1;
|
data->dns_err = 1;
|
||||||
grub_errno = 0;
|
grub_errno = GRUB_ERR_NONE;
|
||||||
return GRUB_ERR_NONE;
|
goto out;
|
||||||
}
|
}
|
||||||
grub_dprintf ("dns", "CNAME %s\n", data->name);
|
grub_dprintf ("dns", "CNAME %s\n", data->name);
|
||||||
if (grub_strcmp (redirect_save, data->name) == 0)
|
if (grub_strcmp (redirect_save, data->name) == 0)
|
||||||
{
|
{
|
||||||
data->dns_err = 1;
|
data->dns_err = 1;
|
||||||
grub_free (redirect_save);
|
goto out;
|
||||||
return GRUB_ERR_NONE;
|
|
||||||
}
|
}
|
||||||
goto reparse;
|
goto reparse;
|
||||||
}
|
}
|
||||||
@@ -440,6 +420,8 @@ recv_hook (grub_net_udp_socket_t sock __attribute__ ((unused)),
|
|||||||
*data->naddresses
|
*data->naddresses
|
||||||
* sizeof (dns_cache[h].addresses[0]));
|
* sizeof (dns_cache[h].addresses[0]));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
out:
|
||||||
grub_netbuff_free (nb);
|
grub_netbuff_free (nb);
|
||||||
grub_free (redirect_save);
|
grub_free (redirect_save);
|
||||||
return GRUB_ERR_NONE;
|
return GRUB_ERR_NONE;
|
||||||
|
|||||||
Reference in new issue
Block a user