public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Simon Marchi <simon.marchi@polymtl.ca>
To: Rian Hunter <rian@thelig.ht>
Cc: gdb-patches@sourceware.org
Subject: Re: fix invalid memory references in gdb/jit.c
Date: Tue, 07 Aug 2018 22:04:00 -0000	[thread overview]
Message-ID: <a85a7f174b56fd5600720812d5709ea0@polymtl.ca> (raw)
In-Reply-To: <8ff4437eb869559c2f917dcb49d3cacd@thelig.ht>

On 2018-08-06 21:05, Rian Hunter wrote:
> These patches fix the case where calling block_open() non-1 amount of
> times causes seg faults. This is when using the custom jit reader API.

Hi Rian,

Thanks for the patch.  Would it be possible to create a test case or 
enhance an existing one to illustrate the problem (and prevent it coming 
back)?  I haven't looked in details, but 
gdb/testsuite/gdb.base/jit-reader.exp looks promising.

Also, could you please try sending your patch using git-send-email next 
time?  It helps a lot when applying it.

> diff --git a/gdb/jit.c b/gdb/jit.c
> index e6b3cc25ca..78295f0dc2 100644
> --- a/gdb/jit.c
> +++ b/gdb/jit.c
> @@ -684,8 +684,11 @@ finalize_symtab (struct gdb_symtab *stab, struct
> objfile *objfile)
>    /* (begin, end) will contain the PC range this entire blockvector
>       spans.  */
>    BLOCKVECTOR_MAP (bv) = NULL;
> -  begin = stab->blocks->begin;
> -  end = stab->blocks->end;
> +  if (stab->blocks)

if (stab->blocks != nullptr)

> +    {
> +      begin = stab->blocks->begin;
> +      end = stab->blocks->end;
> +    }
>    BLOCKVECTOR_NBLOCKS (bv) = actual_nblocks;
> 
>    /* First run over all the gdb_block objects, creating a real block
> @@ -780,7 +783,8 @@ finalize_symtab (struct gdb_symtab *stab, struct
> objfile *objfile)
> 
>    for (gdb_block_iter = stab->blocks, gdb_block_iter_tmp =
> gdb_block_iter->next;
>         gdb_block_iter;
> -       gdb_block_iter = gdb_block_iter_tmp)
> +       gdb_block_iter = gdb_block_iter_tmp,
> +        gdb_block_iter_tmp = (gdb_block_iter ? gdb_block_iter->next  : 
> NULL))
>      {
>        xfree ((void *) gdb_block_iter->name);
>        xfree (gdb_block_iter);

I'm not sure I see how this helps when stab->blocks is NULL.  This is 
how the look initialization is done:

   gdb_block_iter = stab->blocks, gdb_block_iter_tmp = 
gdb_block_iter->next

If stab->blocks is null, gdb_block_iter will be too, and 
"gdb_block_iter->next" will segfault, won't it?

Simon

      reply	other threads:[~2018-08-07 22:04 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-08-07  1:06 Rian Hunter
2018-08-07 22:04 ` Simon Marchi [this message]

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=a85a7f174b56fd5600720812d5709ea0@polymtl.ca \
    --to=simon.marchi@polymtl.ca \
    --cc=gdb-patches@sourceware.org \
    --cc=rian@thelig.ht \
    /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).