public inbox for elfutils@sourceware.org
 help / color / mirror / Atom feed
From: Robert Yang <liezhi.yang@windriver.com>
To: <elfutils-devel@sourceware.org>
Subject: [PATCH V2] libelf/elf_end.c: check data_list.data.d.d_buf before free it
Date: Wed, 29 Aug 2018 08:42:00 -0000	[thread overview]
Message-ID: <1535532800-35485-2-git-send-email-liezhi.yang@windriver.com> (raw)
In-Reply-To: <1535532800-35485-1-git-send-email-liezhi.yang@windriver.com>

The one which actually saves the data is data_list.data.d.d_buf, so check it
before free rawdata_base.

This can fix a segmentation fault when prelink libqb_1.0.3:
prelink: /usr/lib/libqb.so.0.18.2: Symbol section index outside of section numbers

The segmentation fault happens when prelink call elf_end().

Signed-off-by: Robert Yang <liezhi.yang@windriver.com>
---
 libelf/elf_end.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/libelf/elf_end.c b/libelf/elf_end.c
index 160f0b8..5280a70 100644
--- a/libelf/elf_end.c
+++ b/libelf/elf_end.c
@@ -160,14 +160,16 @@ elf_end (Elf *elf)
 		   architecture doesn't require overly stringent
 		   alignment the raw data buffer is the same as the
 		   one used for presenting to the caller.  */
-		if (scn->data_base != scn->rawdata_base)
+		if ((scn->data_base != scn->rawdata_base)
+		    && (scn->data_list.data.d.d_buf != NULL))
 		  free (scn->data_base);
 
 		/* The section data is allocated if we couldn't mmap
 		   the file.  Or if we had to decompress.  */
-		if (elf->map_address == NULL
+		if ((elf->map_address == NULL
 		    || scn->rawdata_base == scn->zdata_base
 		    || (scn->flags & ELF_F_MALLOCED) != 0)
+		    && (scn->data_list.data.d.d_buf != NULL))
 		  free (scn->rawdata_base);
 
 		/* Free the list of data buffers for the section.
-- 
2.7.4

  reply	other threads:[~2018-08-29  8:42 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-08-29  8:42 [PATCH V1] " Robert Yang
2018-08-29  8:42 ` Robert Yang [this message]
2018-08-30 19:57   ` [PATCH V2] " Mark Wielaard
2018-08-31  2:14     ` Robert Yang
2018-08-31  9:35       ` Mark Wielaard
2018-09-03  1:32         ` Robert Yang

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=1535532800-35485-2-git-send-email-liezhi.yang@windriver.com \
    --to=liezhi.yang@windriver.com \
    --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).