Received: from list by lists.gnu.org with archive (Exim 4.90_1) id 1pu9cS-0002VN-RZ for mharc-grub-devel@gnu.org; Wed, 03 May 2023 06:21:56 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pu9cL-0002Mu-Rt for grub-devel@gnu.org; Wed, 03 May 2023 06:21:50 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pu9cK-0007cI-6s for grub-devel@gnu.org; Wed, 03 May 2023 06:21:49 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1683109307; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=h3GpP5uuYgbao7pg/MS0rA9kUPdeiMYOWByB1SHHKfA=; b=gdDAJ34+4UZNftO6ZNi2Bo5UOlADrTS9/6bYhrbV8i/2MWwrI/k5obYjfLiAkdC6koioZS Va0c8z3cZwdh5P/lhQbJa9ljDXIUMtKArfMaKIMEn06u7quIXNk4naF9zurm4TbyeopJM8 ncwmNrT1j4BIsxgr1XWaioH1NI8rjgI= Received: from mail-wm1-f71.google.com (mail-wm1-f71.google.com [209.85.128.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-586-Apjh9jiVN3i5JypSyVnAaw-1; Wed, 03 May 2023 06:21:46 -0400 X-MC-Unique: Apjh9jiVN3i5JypSyVnAaw-1 Received: by mail-wm1-f71.google.com with SMTP id 5b1f17b1804b1-3f1757ebb1eso15234685e9.2 for ; Wed, 03 May 2023 03:21:45 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1683109304; x=1685701304; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=h3GpP5uuYgbao7pg/MS0rA9kUPdeiMYOWByB1SHHKfA=; b=hAU/1OujG/Y/2VSzCCYzVM5puTSVJ+zde75dd9eVWJiZsN3RqRAk559kUjUyC0Gznh 0VsfzJkSmZc5Z7ZrPWUyNSoeSmtjVnNmJs2mXglN6ruwygsfSnbsbprPImXg2JD16LcR V8+JAdDa1mO4xg4r5HmpZnAzH64r2RNmrKOKh6VB40lYXgzS4Usf+LrTOLMoiVzMCZCk A+JpmhZrQnwIK/NWhs/6zIzlovb+7Z4UWN/+L8qKPJQiPNPIIP6+CEHGQ6w/9LXMc1z5 8jTpY2LjVn8akOERTmTSKzuh9spqRJ4livlT+XM4NF34uX4CECydgm0kS5+2EAzwGkTF yenQ== X-Gm-Message-State: AC+VfDwGsqYNcbLvQD67ttH0TIvAn0dbYTteFpb2Y0AivWp6zORqLtMu /w2LUC4nD42c7o3wHd2behSaEGhOmIX3bvjXB9xu/1zkqFbgKUYY9h91xJ30rheh3NTjzbEIscD y+jEWFAy3REIm0olmxIus2VlA2z0oYPRyEMnZH+GpIU1Pa43IA/pG3Y4O9WzCahzueZXk05E= X-Received: by 2002:a05:600c:2198:b0:3ee:4ff0:83d6 with SMTP id e24-20020a05600c219800b003ee4ff083d6mr13444782wme.40.1683109304742; Wed, 03 May 2023 03:21:44 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5cvJ0C8EjDci0rrXGoxl7em+o+Fm+gkGNxXgYdK6Vwx2YZNQgPVRk0t2F8TQ4voKeDThb3Mg== X-Received: by 2002:a05:600c:2198:b0:3ee:4ff0:83d6 with SMTP id e24-20020a05600c219800b003ee4ff083d6mr13444760wme.40.1683109304339; Wed, 03 May 2023 03:21:44 -0700 (PDT) Received: from p1.redhat.com (ip-62-129-184-28.evc.net. [62.129.184.28]) by smtp.gmail.com with ESMTPSA id f12-20020a7bcc0c000000b003f17848673fsm1439618wmh.27.2023.05.03.03.21.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 03 May 2023 03:21:43 -0700 (PDT) From: =?UTF-8?q?Renaud=20M=C3=A9trich?= To: grub-devel@gnu.org Cc: =?UTF-8?q?Renaud=20M=C3=A9trich?= , dkiper@net-space.pl Subject: [PATCH v2 3/3] dns: fix lookup error when no IPv6 is returned Date: Wed, 3 May 2023 12:21:31 +0200 Message-Id: <20230503102131.59126-3-rmetrich@redhat.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230503102131.59126-1-rmetrich@redhat.com> References: <20230503102131.59126-1-rmetrich@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Received-SPF: pass client-ip=170.10.133.124; envelope-from=rmetrich@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -22 X-Spam_score: -2.3 X-Spam_bar: -- X-Spam_report: (-2.3 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.171, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: grub-devel@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: The development of GNU GRUB List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 03 May 2023 10:21:50 -0000 When trying to resolve DNS names into IP addresses, the DNS code fails from time to time with the following error: -------- 8< ---------------- 8< ---------------- 8< ---------------- 8< -------- error: ../../grub-core/net/dns.c:688:no DNS record found. -------- 8< ---------------- 8< ---------------- 8< ---------------- 8< -------- This happens when both IPv4 and IPv6 queries are performed against the DNS server (e.g. 8.8.8.8) but there is no IP returned for IPv6 query, as shown below: -------- 8< ---------------- 8< ---------------- 8< ---------------- 8< -------- grub> net_del_dns 192.168.122.1 grub> net_add_dns 8.8.8.8 grub> net_nslookup ipv4.test-ipv6.com error: ../../grub-core/net/dns.c:688:no DNS record found. grub> net_nslookup ipv4.test-ipv6.com 216.218.228.115 -------- 8< ---------------- 8< ---------------- 8< ---------------- 8< -------- The root cause is the code exiting prematurely when the data->addresses buffer has been allocated in recv_hook(), even if there was no address returned last time recv_hook() executed. Signed-off-by: Renaud Métrich --- grub-core/net/dns.c | 22 ++++++---------------- 1 file changed, 6 insertions(+), 16 deletions(-) diff --git a/grub-core/net/dns.c b/grub-core/net/dns.c index 6993a4aba..2dfb98d98 100644 --- a/grub-core/net/dns.c +++ b/grub-core/net/dns.c @@ -261,7 +261,7 @@ recv_hook (grub_net_udp_socket_t sock __attribute__ ((unused)), /* Code apparently assumed that only one packet is received as response. We may get multiple responses due to network condition, so check here and quit early. */ - if (*data->addresses) + if (*data->naddresses) goto out; head = (struct dns_header *) nb->data; @@ -305,11 +305,7 @@ recv_hook (grub_net_udp_socket_t sock __attribute__ ((unused)), grub_uint32_t ttl = 0; grub_uint16_t length; if (ptr >= nb->tail) - { - if (!*data->naddresses) - grub_free (*data->addresses); - goto out; - } + goto out; ignored = !check_name (ptr, nb->data, nb->tail, data->name); while (ptr < nb->tail && !((*ptr & 0xc0) || *ptr == 0)) ptr += *ptr + 1; @@ -317,11 +313,7 @@ recv_hook (grub_net_udp_socket_t sock __attribute__ ((unused)), ptr++; ptr++; if (ptr + 10 >= nb->tail) - { - if (!*data->naddresses) - grub_free (*data->addresses); - goto out; - } + goto out; if (*ptr++ != 0) ignored = 1; class = *ptr++; @@ -337,11 +329,7 @@ recv_hook (grub_net_udp_socket_t sock __attribute__ ((unused)), length = *ptr++ << 8; length |= *ptr++; if (ptr + length > nb->tail) - { - if (!*data->naddresses) - grub_free (*data->addresses); - goto out; - } + goto out; if (!ignored) { if (ttl_all > ttl) @@ -429,6 +417,8 @@ recv_hook (grub_net_udp_socket_t sock __attribute__ ((unused)), out: grub_netbuff_free (nb); grub_free (redirect_save); + if (!*data->naddresses) + grub_free (*data->addresses); return GRUB_ERR_NONE; } -- 2.40.1