public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
From: Ilya Leoshkevich <iii@linux.ibm.com>
To: Jan Beulich <jbeulich@suse.com>
Cc: binutils@sourceware.org, Jose Marchesi <jose.marchesi@oracle.com>
Subject: Re: [PATCH] gas: fix building tc-bpf.c on s390x
Date: Fri, 28 Apr 2023 11:37:58 +0200	[thread overview]
Message-ID: <78d8001581eafec9a53ac440d6e43b8c52362068.camel@linux.ibm.com> (raw)
In-Reply-To: <b933eec2-09c3-60f5-f420-e7bde736e676@suse.com>

On Fri, 2023-04-28 at 08:42 +0200, Jan Beulich wrote:
> On 27.04.2023 14:56, Ilya Leoshkevich via Binutils wrote:
> > --- a/gas/config/tc-bpf.c
> > +++ b/gas/config/tc-bpf.c
> > @@ -885,7 +885,7 @@ get_token (const char **insn, char *token,
> > size_t *tlen)
> >      } while (0)
> >  
> >    const char *str = *insn;
> > -  char ch, ch2 = 0;
> > +  signed char ch, ch2 = 0;
> 
> But this doesn't make things any better. If you grep for uses of EOF
> in
> gas, you'll find that the corresponding variables typically are of
> type
> int, and that's what I expect you want to use here as well.

You are right, int is better. Thanks.

> > @@ -1362,7 +1362,7 @@ bpf_pseudoc_to_normal_syntax (const char
> > *str, char **errmsg)
> >      } while (0)
> >  
> >    enum bpf_token_type ttype;
> > -  enum bpf_token_type bpf_endianness,
> > +  enum bpf_token_type bpf_endianness = BPF_UNKNOWN,
> 
> The variable surely wants an initializer, but I'm uncertain whether
> the
> one you picked is suitable. I don't know bpf, but I see only two
> options:
> There is a default endianness, in which case that wants to be the
> initializer. Or endianness needs to be specified explicitly before
> any
> of the constructs leading to build_bpf_endianness() may be used. In
> that
> case the initializer chosen is perhaps fine, but the variable then
> still
> having that value would need to be diagnosed. With what you've done
> we
> now end up with an out of bounds array access in
> build_bpf_endianness().
> 
> You would better have Cc-ed the arch maintainer anyway; doing so now.

In that regard the patch does not make things worse.
If we end up not initializing the variable on the intended path, with
today's code we would still have an OOB access (but with a random
offset). The goal here is only to silence the warning, which I believe
is emitted incorrectly.

If I read the FSM correctly, this can only happen due to a bug, no
user input (valid or invalid) should be leading to this. So, just to be
on the safe side, I would add gas_assert() to build_bpf_endianness().

> Jan


      reply	other threads:[~2023-04-28  9:39 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-04-27 12:56 Ilya Leoshkevich
2023-04-28  6:42 ` Jan Beulich
2023-04-28  9:37   ` Ilya Leoshkevich [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=78d8001581eafec9a53ac440d6e43b8c52362068.camel@linux.ibm.com \
    --to=iii@linux.ibm.com \
    --cc=binutils@sourceware.org \
    --cc=jbeulich@suse.com \
    --cc=jose.marchesi@oracle.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).