144 lines
3.8 KiB
Diff
144 lines
3.8 KiB
Diff
From 47a171178809d67996a5dc470622ab6d3760cfa6 Mon Sep 17 00:00:00 2001
|
|
From: Fedora Ninjas <grub2-owner@fedoraproject.org>
|
|
Date: Tue, 28 Jan 2025 15:27:16 +0000
|
|
Subject: [PATCH 1/3] net/dns: Simplify error handling of recv_hook() function
|
|
MIME-Version: 1.0
|
|
Content-Type: text/plain; charset=UTF-8
|
|
Content-Transfer-Encoding: 8bit
|
|
|
|
Signed-off-by: Renaud Métrich <rmetrich@redhat.com>
|
|
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
|
|
|
|
Orabug: 37539625
|
|
Modified-by: Alex Burmashev <alexander.burmashev@oracle.com>
|
|
Signed-off-by: Alex Burmashev <alexander.burmashev@oracle.com>
|
|
---
|
|
grub-core/net/dns.c | 51 +++++++++++++++------------------------------
|
|
1 file changed, 17 insertions(+), 34 deletions(-)
|
|
|
|
diff --git a/grub-core/net/dns.c b/grub-core/net/dns.c
|
|
index e9edf5d..8ba4e54 100644
|
|
--- a/grub-core/net/dns.c
|
|
+++ b/grub-core/net/dns.c
|
|
@@ -262,42 +262,27 @@ recv_hook (grub_net_udp_socket_t sock __attribute__ ((unused)),
|
|
We may get multiple responses due to network condition, so check here
|
|
and quit early. */
|
|
if (*data->addresses)
|
|
- {
|
|
- grub_netbuff_free (nb);
|
|
- return GRUB_ERR_NONE;
|
|
- }
|
|
+ goto out;
|
|
|
|
head = (struct dns_header *) nb->data;
|
|
ptr = (grub_uint8_t *) (head + 1);
|
|
if (ptr >= nb->tail)
|
|
- {
|
|
- grub_netbuff_free (nb);
|
|
- return GRUB_ERR_NONE;
|
|
- }
|
|
-
|
|
+ goto out;
|
|
+
|
|
if (head->id != data->id)
|
|
- {
|
|
- grub_netbuff_free (nb);
|
|
- return GRUB_ERR_NONE;
|
|
- }
|
|
+ goto out;
|
|
if (!(head->flags & FLAGS_RESPONSE) || (head->flags & FLAGS_OPCODE))
|
|
- {
|
|
- grub_netbuff_free (nb);
|
|
- return GRUB_ERR_NONE;
|
|
- }
|
|
+ goto out;
|
|
if (head->ra_z_r_code & ERRCODE_MASK)
|
|
{
|
|
data->dns_err = 1;
|
|
- grub_netbuff_free (nb);
|
|
- return GRUB_ERR_NONE;
|
|
+ goto out;
|
|
}
|
|
+
|
|
for (i = 0; i < grub_be_to_cpu16 (head->qdcount); i++)
|
|
{
|
|
if (ptr >= nb->tail)
|
|
- {
|
|
- grub_netbuff_free (nb);
|
|
- return GRUB_ERR_NONE;
|
|
- }
|
|
+ goto out;
|
|
while (ptr < nb->tail && !((*ptr & 0xc0) || *ptr == 0))
|
|
ptr += *ptr + 1;
|
|
if (ptr < nb->tail && (*ptr & 0xc0))
|
|
@@ -310,8 +295,7 @@ recv_hook (grub_net_udp_socket_t sock __attribute__ ((unused)),
|
|
if (!*data->addresses)
|
|
{
|
|
grub_errno = GRUB_ERR_NONE;
|
|
- grub_netbuff_free (nb);
|
|
- return GRUB_ERR_NONE;
|
|
+ goto out;
|
|
}
|
|
reparse_ptr = ptr;
|
|
reparse:
|
|
@@ -325,7 +309,7 @@ recv_hook (grub_net_udp_socket_t sock __attribute__ ((unused)),
|
|
{
|
|
if (!*data->naddresses)
|
|
grub_free (*data->addresses);
|
|
- return GRUB_ERR_NONE;
|
|
+ goto out;
|
|
}
|
|
ignored = !check_name (ptr, nb->data, nb->tail, data->name);
|
|
while (ptr < nb->tail && !((*ptr & 0xc0) || *ptr == 0))
|
|
@@ -337,8 +321,7 @@ recv_hook (grub_net_udp_socket_t sock __attribute__ ((unused)),
|
|
{
|
|
if (!*data->naddresses)
|
|
grub_free (*data->addresses);
|
|
- grub_netbuff_free (nb);
|
|
- return GRUB_ERR_NONE;
|
|
+ goto out;
|
|
}
|
|
if (*ptr++ != 0)
|
|
ignored = 1;
|
|
@@ -358,8 +341,7 @@ recv_hook (grub_net_udp_socket_t sock __attribute__ ((unused)),
|
|
{
|
|
if (!*data->naddresses)
|
|
grub_free (*data->addresses);
|
|
- grub_netbuff_free (nb);
|
|
- return GRUB_ERR_NONE;
|
|
+ goto out;
|
|
}
|
|
if (!ignored)
|
|
{
|
|
@@ -400,15 +382,14 @@ recv_hook (grub_net_udp_socket_t sock __attribute__ ((unused)),
|
|
if (!data->name)
|
|
{
|
|
data->dns_err = 1;
|
|
- grub_errno = 0;
|
|
- return GRUB_ERR_NONE;
|
|
+ grub_errno = GRUB_ERR_NONE;
|
|
+ goto out;
|
|
}
|
|
grub_dprintf ("dns", "CNAME %s\n", data->name);
|
|
if (grub_strcmp (redirect_save, data->name) == 0)
|
|
{
|
|
data->dns_err = 1;
|
|
- grub_free (redirect_save);
|
|
- return GRUB_ERR_NONE;
|
|
+ goto out;
|
|
}
|
|
goto reparse;
|
|
}
|
|
@@ -440,6 +421,8 @@ recv_hook (grub_net_udp_socket_t sock __attribute__ ((unused)),
|
|
*data->naddresses
|
|
* sizeof (dns_cache[h].addresses[0]));
|
|
}
|
|
+
|
|
+ out:
|
|
grub_netbuff_free (nb);
|
|
grub_free (redirect_save);
|
|
return GRUB_ERR_NONE;
|
|
--
|
|
2.43.5
|
|
|