public inbox for elfutils@sourceware.org
 help / color / mirror / Atom feed
From: Mark Wielaard <mark@klomp.org>
To: Noah Sanci <nsanci@redhat.com>, elfutils-devel@sourceware.org
Subject: Re: [Bug debuginfod/27983] ignore duplicate urls
Date: Fri, 23 Jul 2021 20:34:05 +0200	[thread overview]
Message-ID: <7b021d11929e451d77961ab183cd97f3329a6dce.camel@klomp.org> (raw)
In-Reply-To: <CAJXA7qjbXSHs_8gk11y0k3=1iNUwspERYB_KxtcKDZdk-wrQsQ@mail.gmail.com>

Hi Noah,

On Thu, 2021-07-22 at 15:22 -0400, Noah Sanci via Elfutils-devel wrote:
> PR27983 improvements attached

Please do mention the improvements you made. It really does help others
see what you thought of. So in this case use asprintf instead of calloc
plus sprintf, and (re)use tmpurl instead of strduping it and freeing.
Both good improvements.

I really like this variant of the patch. Nice work.

There is one possible issue with the reallocarray call (realloc[array]
is terrible that way, sorry). See below.

Also, could you please rebase this patch on top of master, there have
been various changes to debuginfod-client.c and it would be nice to see
how the patch interacts with those.

> +      else
> +        {
> +          num_urls++;
> +          server_url_list = reallocarray(server_url_list, num_urls,
> +                                         sizeof(char*));
> +          if (server_url_list == NULL)
> +            {
> +              rc = -ENOMEM;
> +              goto out1;
> +            }
> +          server_url_list[num_urls-1] = tmp_url;
> +        }

Note how reallocarray returns NULL on failure.
This means you lost the original server_url_list pointer.
And so when you then do cleanup by going to out1...

> + out1:
> +  for (int i = 0; i < num_urls; ++i)
> +    free(server_url_list[i]);
> +  free(server_url_list);

You will crash because server_url_list is NULL here, so
server_url_list[i] is a bad dereference...

Bleah. Like I said, the realloc(array) interface is really bad :{

To use reallocarray safely you need to use a temp and only set it after
the call succeeds.

char **realloc_ptr = reallocarray (...);
if (realloc_ptr == NULL)
  {
    rc = -ENOMEM;
    goto out1;
  }
server_url_list = realloc_ptr;
server_url_list[num_urls-1] = ...;

The rest of the patch looks good.

Thanks,

Mark

  reply	other threads:[~2021-07-23 18:34 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-07-09 19:12 Noah Sanci
2021-07-14 16:36 ` Mark Wielaard
2021-07-19 13:31   ` Noah Sanci
2021-07-20 14:42     ` Mark Wielaard
2021-07-22 16:25       ` Noah Sanci
2021-07-22 19:22         ` Noah Sanci
2021-07-23 18:34           ` Mark Wielaard [this message]
2021-07-26 16:29             ` Noah Sanci
2021-07-28 14:55               ` Mark Wielaard
2021-07-28 16:23                 ` Noah Sanci
2021-07-29 12:20                   ` Mark Wielaard

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=7b021d11929e451d77961ab183cd97f3329a6dce.camel@klomp.org \
    --to=mark@klomp.org \
    --cc=elfutils-devel@sourceware.org \
    --cc=nsanci@redhat.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 read-only IMAP folder(s) and NNTP newsgroup(s).