Bug 25360 - memory leak in readelf, get_data
Summary: memory leak in readelf, get_data
Status: RESOLVED FIXED
Alias: None
Product: binutils
Classification: Unclassified
Component: binutils (show other bugs)
Version: 2.32
: P2 normal
Target Milestone: 2.34
Assignee: Alan Modra
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2020-01-10 13:45 UTC by Heqing HUANG
Modified: 2020-01-13 12:28 UTC (History)
0 users

See Also:
Host:
Target:
Build:
Last reconfirmed:


Attachments
POC file (2.43 KB, application/x-sharedlib)
2020-01-10 13:45 UTC, Heqing HUANG
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Heqing HUANG 2020-01-10 13:45:41 UTC
Created attachment 12181 [details]
POC file

Hi, there.

There is a memory leak in file binutils/readelf.c, get_data function.

Here is the reproducing environment and procedure:

Distributor ID:	Ubuntu
Description:	Ubuntu 16.04.6 LTS
Release:	16.04
Codename:	xenial
gcc:            5.4.0

compilation:
CFLAGS="-fsanitize=address,undefined" ./configure

./readelf -agteSdcWw --dyn-syms -D poc


Here is the error message:

=================================================================
==15608==ERROR: LeakSanitizer: detected memory leaks

Direct leak of 69 byte(s) in 1 object(s) allocated from:
    #0 0x7ffff6f02602 in malloc (/usr/lib/x86_64-linux-gnu/libasan.so.2+0x98602)
    #1 0x40b2a1 in get_data (/playground/playground/binutils-2.32-r/binutils-2.32/binutils/readelf+0x40b2a1)
    #2 0x478a80 in process_notes_at (/playground/playground/binutils-2.32-r/binutils-2.32/binutils/readelf+0x478a80)
    #3 0x47961f in process_corefile_note_segments (/playground/playground/binutils-2.32-r/binutils-2.32/binutils/readelf+0x47961f)
    #4 0x47a0f6 in process_note_sections (/playground/playground/binutils-2.32-r/binutils-2.32/binutils/readelf+0x47a0f6)
    #5 0x47a195 in process_notes (/playground/playground/binutils-2.32-r/binutils-2.32/binutils/readelf+0x47a195)
    #6 0x47c930 in process_object (/playground/playground/binutils-2.32-r/binutils-2.32/binutils/readelf+0x47c930)
    #7 0x47e950 in process_file (/playground/playground/binutils-2.32-r/binutils-2.32/binutils/readelf+0x47e950)
    #8 0x47ecd1 in main (/playground/playground/binutils-2.32-r/binutils-2.32/binutils/readelf+0x47ecd1)
    #9 0x7ffff5db382f in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x2082f)

SUMMARY: AddressSanitizer: 69 byte(s) leaked in 1 allocation(s).

Regards,
Comment 1 Sourceware Commits 2020-01-13 12:27:28 UTC
The master branch has been updated by Alan Modra <amodra@sourceware.org>:

https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=a4f2b7c5d931f2aa27851b59ae5817a6ee43cfcb

commit a4f2b7c5d931f2aa27851b59ae5817a6ee43cfcb
Author: Alan Modra <amodra@gmail.com>
Date:   Mon Jan 13 22:53:02 2020 +1030

    Re: PR23560, PR23561, readelf memory leaks
    
    	PR 25360
    	PR 25361
    	Dyslexia strikes again.
    
    Fix git commit a788aedd86da983faf0afef3cb41461118a2e9f2 ChangeLog.
Comment 2 Alan Modra 2020-01-13 12:28:10 UTC
Fixed.