]> code.ossystems Code Review - openembedded-core.git/blob
b26ed99f6507d972e2d83fce63bb6245fca1d0c3
[openembedded-core.git] /
1 From e571cbd0c20085ec71969971f19280b5de95cfb7 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
5
6 The one which actually saves the data is data_list.data.d.d_buf, so check it
7 before free rawdata_base.
8
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
11
12 The segmentation fault happens when prelink call elf_end().
13
14 Upstream-Status: Submitted [https://sourceware.org/ml/elfutils-devel/2018-q3/msg00085.html]
15
16 Signed-off-by: Robert Yang <liezhi.yang@windriver.com>
17
18 ---
19  libelf/elf_end.c | 6 ++++--
20  1 file changed, 4 insertions(+), 2 deletions(-)
21
22 diff --git a/libelf/elf_end.c b/libelf/elf_end.c
23 index 160f0b8..5280a70 100644
24 --- a/libelf/elf_end.c
25 +++ b/libelf/elf_end.c
26 @@ -160,14 +160,16 @@ elf_end (Elf *elf)
27                    architecture doesn't require overly stringent
28                    alignment the raw data buffer is the same as the
29                    one used for presenting to the caller.  */
30 -               if (scn->data_base != scn->rawdata_base)
31 +               if ((scn->data_base != scn->rawdata_base)
32 +                   && (scn->data_list.data.d.d_buf != NULL))
33                   free (scn->data_base);
34  
35                 /* The section data is allocated if we couldn't mmap
36                    the file.  Or if we had to decompress.  */
37 -               if (elf->map_address == NULL
38 +               if ((elf->map_address == NULL
39                     || scn->rawdata_base == scn->zdata_base
40                     || (scn->flags & ELF_F_MALLOCED) != 0)
41 +                   && (scn->data_list.data.d.d_buf != NULL))
42                   free (scn->rawdata_base);
43  
44                 /* Free the list of data buffers for the section.