grub-devel.gnu.org archive mirror
 help / color / mirror / Atom feed
From: Andrei Borzenkov <arvidjaar@gmail.com>
To: The development of GNU GRUB <grub-devel@gnu.org>, kernel-team@fb.com
Cc: Josef Bacik <jbacik@fb.com>
Subject: Re: [PATCH] net: don't free uninitialized sockets in dns
Date: Wed, 19 Aug 2015 19:36:53 +0300	[thread overview]
Message-ID: <55D4B0A5.9060101@gmail.com> (raw)
In-Reply-To: <1439921023-3547412-1-git-send-email-jbacik@fb.com>

[-- Attachment #1: Type: text/plain, Size: 874 bytes --]

18.08.2015 21:03, Josef Bacik пишет:
> If we cannot open a connection to our dns server we will have NULL sockets in
> our array, so don't do the cleanup on any sockets that didn't get created.
>

We can avoid having holes to start with. Could you test attached patch?

> Signed-off-by: Josef Bacik <jbacik@fb.com>
> ---
>   grub-core/net/dns.c | 5 ++++-
>   1 file changed, 4 insertions(+), 1 deletion(-)
>
> diff --git a/grub-core/net/dns.c b/grub-core/net/dns.c
> index 9d0c8fc..c356318 100644
> --- a/grub-core/net/dns.c
> +++ b/grub-core/net/dns.c
> @@ -601,7 +601,10 @@ grub_net_dns_lookup (const char *name,
>     grub_free (data.name);
>     grub_netbuff_free (nb);
>     for (j = 0; j < send_servers; j++)
> -    grub_net_udp_close (sockets[j]);
> +    {
> +      if (sockets[j])
> +	grub_net_udp_close (sockets[j]);
> +    }
>
>     grub_free (sockets);
>
>


[-- Attachment #2: dns-null-free.patch --]
[-- Type: text/x-patch, Size: 1812 bytes --]

From: Andrei Borzenkov <arvidjaar@gmail.com>
Subject: [PATCH] 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>


---
 grub-core/net/dns.c | 16 +++++++---------
 1 file changed, 7 insertions(+), 9 deletions(-)

diff --git a/grub-core/net/dns.c b/grub-core/net/dns.c
index 9d0c8fc..953f3be 100644
--- a/grub-core/net/dns.c
+++ b/grub-core/net/dns.c
@@ -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;
-- 
tg: (ba218c1..) u/dns-NULL-dereference (depends on: master)

  reply	other threads:[~2015-08-21  0:42 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-08-18 18:03 [PATCH] net: don't free uninitialized sockets in dns Josef Bacik
2015-08-19 16:36 ` Andrei Borzenkov [this message]
2015-10-10  7:03   ` Andrei Borzenkov
2015-10-12 15:02     ` Josef Bacik

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=55D4B0A5.9060101@gmail.com \
    --to=arvidjaar@gmail.com \
    --cc=grub-devel@gnu.org \
    --cc=jbacik@fb.com \
    --cc=kernel-team@fb.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).