1 From d68822e93c57c3fbb77b93eada5986d2240157c2 Mon Sep 17 00:00:00 2001
2 From: Robert Yang <liezhi.yang@windriver.com>
3 Date: Thu, 16 Aug 2018 09:58:26 +0800
4 Subject: [PATCH] libelf/elf_end.c: check data_list.data.d.d_buf before free it
6 The one which actually saves the data is data_list.data.d.d_buf, so check it
7 before free rawdata_base.
9 This can fix a segmentation fault when prelink libqb_1.0.3:
10 prelink: /usr/lib/libqb.so.0.18.2: Symbol section index outside of section numbers
12 The segmentation fault happens when prelink call elf_end().
14 Upstream-Status: Submitted [https://sourceware.org/ml/elfutils-devel/2018-q3/msg00065.html]
16 Signed-off-by: Robert Yang <liezhi.yang@windriver.com>
18 libelf/elf_end.c | 3 ++-
19 1 file changed, 2 insertions(+), 1 deletion(-)
21 diff --git a/libelf/elf_end.c b/libelf/elf_end.c
22 index 160f0b8..5388e80 100644
23 --- a/libelf/elf_end.c
24 +++ b/libelf/elf_end.c
25 @@ -165,9 +165,10 @@ elf_end (Elf *elf)
27 /* The section data is allocated if we couldn't mmap
28 the file. Or if we had to decompress. */
29 - if (elf->map_address == NULL
30 + if ((elf->map_address == NULL
31 || scn->rawdata_base == scn->zdata_base
32 || (scn->flags & ELF_F_MALLOCED) != 0)
33 + && (scn->data_list.data.d.d_buf != NULL))
34 free (scn->rawdata_base);
36 /* Free the list of data buffers for the section.