qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Peter Maydell <peter.maydell@linaro.org>
To: "Alex Bennée" <alex.bennee@linaro.org>
Cc: QEMU Developers <qemu-devel@nongnu.org>
Subject: Re: [PATCH v1 1/7] elf-ops: bail out if we have no function symbols
Date: Fri, 27 Mar 2020 11:45:20 +0000	[thread overview]
Message-ID: <CAFEAcA_g+qQMYF699LUf2W-aYxWDNEwED=kdA+Eo2w_anW6A2A@mail.gmail.com> (raw)
In-Reply-To: <20200327094945.23768-2-alex.bennee@linaro.org>

On Fri, 27 Mar 2020 at 09:50, Alex Bennée <alex.bennee@linaro.org> wrote:
>
> It's perfectly possible to have no function symbols in your elf file
> and if we do the undefined behaviour sanitizer rightly complains about
> us passing NULL to qsort. Check nsyms before we go ahead.
>
> Signed-off-by: Alex Bennée <alex.bennee@linaro.org>
> ---
>  include/hw/elf_ops.h | 7 ++++++-
>  1 file changed, 6 insertions(+), 1 deletion(-)
>
> diff --git a/include/hw/elf_ops.h b/include/hw/elf_ops.h
> index a1411bfcab6..b5d4074d1e3 100644
> --- a/include/hw/elf_ops.h
> +++ b/include/hw/elf_ops.h
> @@ -170,8 +170,13 @@ static int glue(load_symbols, SZ)(struct elfhdr *ehdr, int fd, int must_swab,
>          }
>          i++;
>      }
> -    syms = g_realloc(syms, nsyms * sizeof(*syms));
>
> +    /* check we have symbols left */
> +    if (nsyms == 0) {
> +        goto fail;
> +    }
> +
> +    syms = g_realloc(syms, nsyms * sizeof(*syms));
>      qsort(syms, nsyms, sizeof(*syms), glue(symcmp, SZ));
>      for (i = 0; i < nsyms - 1; i++) {
>          if (syms[i].st_size == 0) {

If "ELF file has no symbols" is valid, it's a bit odd for
load_symbols to report it as a failure by returning -1.
This only works because load_elf (the only caller) just
ignores the return value entirely. OTOH I suppose you
could argue that we can just ignore any oddity in the
attempt to load symbols (eg bogus/malformad symtab section).
If so, we should probably drop the return value from
load_symbols().

thanks
-- PMM


  parent reply	other threads:[~2020-03-27 11:46 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-03-27  9:49 [PATCH for 5.0 v1 0/7] A selection of sanitiser fixes Alex Bennée
2020-03-27  9:49 ` [PATCH v1 1/7] elf-ops: bail out if we have no function symbols Alex Bennée
2020-03-27 10:53   ` Philippe Mathieu-Daudé
2020-03-27 11:10     ` Philippe Mathieu-Daudé
2020-03-27 11:45   ` Peter Maydell [this message]
2020-03-27 22:09   ` Richard Henderson
2020-03-27  9:49 ` [PATCH v1 2/7] linux-user: protect fcntl64 with an #ifdef Alex Bennée
2020-03-27 10:40   ` Laurent Vivier
2020-03-27 22:10   ` Richard Henderson
2020-03-27  9:49 ` [PATCH v1 3/7] tests/tcg: remove extraneous pasting macros Alex Bennée
2020-03-27 10:54   ` Philippe Mathieu-Daudé
2020-03-27 22:11   ` Richard Henderson
2020-03-27  9:49 ` [PATCH v1 4/7] linux-user: more debug for init_guest_space Alex Bennée
2020-03-27 10:50   ` Laurent Vivier
2020-03-27  9:49 ` [PATCH v1 5/7] fpu/softfloat: avoid undefined behaviour when normalising empty sigs Alex Bennée
2020-03-27 10:09   ` Peter Maydell
2020-03-27 22:27     ` Richard Henderson
2020-03-27 22:33       ` Peter Maydell
2020-03-27 10:13   ` Aleksandar Markovic
2020-03-27 10:31     ` Alex Bennée
2020-03-27  9:49 ` [PATCH v1 6/7] target/xtensa: add FIXME for translation memory leak Alex Bennée
2020-03-27  9:49 ` [PATCH v1 7/7] gdbstub: fix compiler complaining Alex Bennée
2020-03-27 10:56   ` Philippe Mathieu-Daudé
2020-03-27 10:53 ` [PATCH for 5.0 v1 0/7] A selection of sanitiser fixes no-reply

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='CAFEAcA_g+qQMYF699LUf2W-aYxWDNEwED=kdA+Eo2w_anW6A2A@mail.gmail.com' \
    --to=peter.maydell@linaro.org \
    --cc=alex.bennee@linaro.org \
    --cc=qemu-devel@nongnu.org \
    /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).