public inbox for elfutils@sourceware.org
 help / color / mirror / Atom feed
From: Mark Wielaard <mark@klomp.org>
To: elfutils-devel@sourceware.org
Subject: Re: [PATCH] readelf: Don't allocate string with asprintf, but reuse buffer with sprintf.
Date: Thu, 07 Jun 2018 21:44:00 -0000	[thread overview]
Message-ID: <1528407882-16903-1-git-send-email-mark@klomp.org> (raw)
In-Reply-To: <20180606203750.GC31910@wildebeest.org>

On Mon, Jun 04, 2018 at 07:05:16PM +0200, Mark Wielaard wrote:
> Since we are single threaded we can just use a static result buffer for
> format_dwarf_addr as long as we make sure to print the result before
> calling format_dwarf_addr again. This removes lots of malloc/free calls.

Almost as soon as I checked this in the afl fuzzer detected that we
assumed addresses are max 8 bytes (64bits). So it presented us with
a CU that has an address size of 136 bytes... We dutifully try to
print that large an address into a buffer that has room for just 8
and crash...

First, we should just make sure to always use 32 or 64 bit addresses
(and offsets). There is too much code that really relies on them being
either 4 bytes or 8 bytes.

[PATCH 1/2] libdw: Make sure that address_size and offset_size are 4

Second, it is not really necessary to create a buffer, sprintf into it,
then use that buffer to printf to stdio. Just do it directly.

[PATCH 2/2] readelf: Turn format_print_dwarf into print_dwarf_addr.

Cheers,

Mark

  reply	other threads:[~2018-06-07 21:44 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-06-04 17:05 Mark Wielaard
2018-06-06 20:37 ` Mark Wielaard
2018-06-07 21:44   ` Mark Wielaard [this message]
2018-06-07 21:45     ` [PATCH 1/2] libdw: Make sure that address_size and offset_size are 4 or 8 bytes Mark Wielaard
2018-06-09  8:35       ` Mark Wielaard
2018-06-07 21:46     ` [PATCH 2/2] readelf: Turn format_print_dwarf into print_dwarf_addr Mark Wielaard
2018-06-09  8:38       ` 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=1528407882-16903-1-git-send-email-mark@klomp.org \
    --to=mark@klomp.org \
    --cc=elfutils-devel@sourceware.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 read-only IMAP folder(s) and NNTP newsgroup(s).