Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Alan Modra <amodra@gmail.com>
To: Max Filippov <jcmvbkbc@gmail.com>
Cc: binutils@sourceware.org, gdb-patches@sourceware.org
Subject: Re: xtensa_insnbuf_from_chars buffer overflow checking
Date: Wed, 4 Nov 2026 09:34:23 +1030	[thread overview]
Message-ID: <aupodzXtjwzM7n4Z@squeak.grove.modra.org> (raw)
In-Reply-To: <CAMo8BfKcC5+K=tF9nCka4gx3Bck5KQMGC5Dh1e1TLTHN1Rrp4w@mail.gmail.com>

On Tue, Nov 03, 2026 at 05:22:26AM -0800, Max Filippov wrote:
> On Tue, Nov 3, 2026 at 2:46 AM Alan Modra <amodra@gmail.com> wrote:
> > +/* Wrapper for xtensa_insnbuf_from_chars to convert frag bytes
> > +   to xtensa_insnbuf.  */
> > +
> > +static bool
> > +xtensa_insnbuf_from_frag (xtensa_isa isa, xtensa_insnbuf insnbuf,
> > +                         const fragS *frag, size_t off)
> > +{
> > +  const unsigned char *buf = (const unsigned char *) frag->fr_literal + off;
> > +  size_t len = frag->fr_fix - off;
> > +  gas_assert (frag->fr_fix > off);
> > +  bool ret = xtensa_insnbuf_from_chars (isa, insnbuf, buf, len);
> > +  gas_assert (ret);
> 
> This assertion is triggered when assembling the attached source with
> option --text-section-literals with the following backtrace:

Wrong testcase attached?  I don't reproduce the assertion here.

> #0  0x00007ffff7e062e0 in exit () from /lib/x86_64-linux-gnu/libc.so.6
> #1  0x000055555566b9ac in xexit ()
> #2  0x00005555555a2c86 in as_abort ()
> #3  0x00005555555b917f in xtensa_insnbuf_from_frag.isra ()
> #4  0x00005555555b956f in frag_format_size ()
> #5  0x00005555555bc4fe in get_aligned_diff ()
> #6  0x00005555555bc8e1 in relax_frag_for_align ()
> #7  0x00005555555c8a6a in xtensa_relax_frag ()
> #8  0x00005555555b52f8 in relax_segment ()
> #9  0x00005555555b5762 in relax_seg ()
> #10 0x00005555555dbcdf in bfd_map_over_sections ()
> #11 0x00005555555b589a in write_object_file ()
> #12 0x000055555558e071 in main ()
> 
> ...
> 
> > diff --git a/include/xtensa-isa.h b/include/xtensa-isa.h
> > index 5c25f122d29..4818559ff94 100644
> > --- a/include/xtensa-isa.h
> > +++ b/include/xtensa-isa.h
> > @@ -210,7 +210,7 @@ extern int
> >  xtensa_insnbuf_to_chars (xtensa_isa isa, const xtensa_insnbuf insn,
> >                          unsigned char *cp, int num_chars);
> >
> > -extern void
> > +extern bool
> 
> Other similar functions in this library have return type `int` and return
> 0 on success and a negative error code on failure. Could this function
> please follow this pattern too? That's because this header is included
> into the generated configuration-specific xtensa-modules.c and does
> not include <stdbool.h> itself.

I can do that for consistency, but I can't say I like the practice of
avoiding bool.  Especially for functions like xtensa_opcode_is_branch
which are used everywhere testing == 1 or > 0 except one place in
xtensa-dis.c.  (Maybe a bug?)

> >  xtensa_insnbuf_from_chars (xtensa_isa isa, xtensa_insnbuf insn,
> >                            const unsigned char *cp, int num_chars);
> >
> ...
> 
> -- 
> Thanks.
> -- Max



-- 
Alan Modra

  reply	other threads:[~2026-11-03 23:05 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-03 10:46 Alan Modra
2026-11-03 13:22 ` Max Filippov
2026-11-03 23:04   ` Alan Modra [this message]
2026-11-04  6:38     ` Max Filippov
2026-11-09  4:20       ` Alan Modra
2026-11-09 14:04         ` Max Filippov

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=aupodzXtjwzM7n4Z@squeak.grove.modra.org \
    --to=amodra@gmail.com \
    --cc=binutils@sourceware.org \
    --cc=gdb-patches@sourceware.org \
    --cc=jcmvbkbc@gmail.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