From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 107679 invoked by alias); 13 Jun 2018 23:10:20 -0000 Mailing-List: contact elfutils-devel-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Post: List-Help: List-Subscribe: Sender: elfutils-devel-owner@sourceware.org Received: (qmail 107655 invoked by uid 89); 13 Jun 2018 23:10:19 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Checked: by ClamAV 0.99.4 on sourceware.org X-Virus-Found: No X-Spam-SWARE-Status: No, score=-26.9 required=5.0 tests=BAYES_00,GIT_PATCH_0,GIT_PATCH_1,GIT_PATCH_2,GIT_PATCH_3,RCVD_IN_DNSWL_NONE,SPF_PASS autolearn=ham version=3.3.2 spammy=insane X-Spam-Status: No, score=-26.9 required=5.0 tests=BAYES_00,GIT_PATCH_0,GIT_PATCH_1,GIT_PATCH_2,GIT_PATCH_3,RCVD_IN_DNSWL_NONE,SPF_PASS autolearn=ham version=3.3.2 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on sourceware.org X-Spam-Level: X-HELO: gnu.wildebeest.org Received: from wildebeest.demon.nl (HELO gnu.wildebeest.org) (212.238.236.112) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 13 Jun 2018 23:10:18 +0000 Received: from librem.wildebeest.org (deer0x15.wildebeest.org [172.31.17.151]) (using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by gnu.wildebeest.org (Postfix) with ESMTPSA id 2CB783000702; Thu, 14 Jun 2018 01:10:15 +0200 (CEST) Received: by librem.wildebeest.org (Postfix, from userid 1000) id E47EE142805; Thu, 14 Jun 2018 01:10:15 +0200 (CEST) From: Mark Wielaard To: elfutils-devel@sourceware.org Cc: Mark Wielaard Subject: [PATCH] readelf: Make sure print_form_data always consumes DW_FORM_strx[1234] data. Date: Wed, 13 Jun 2018 23:10:00 -0000 Message-Id: <20180613231012.19118-1-mark@klomp.org> X-Mailer: git-send-email 2.17.0 X-Spam-Flag: NO X-IsSubscribed: yes X-SW-Source: 2018-q2/txt/msg00214.txt.bz2 Found by afl-fuzz. When printing DW_FORM_strx[1234] data eu-readelf didn't increase readp which meant eu-readelf would keep printing the same line dirs or files encoded with strx[1234] names. This meant that for insane large dir or file counts eu-readelf would just keep printing endlessly because we never reached and of the .debug_line buffer. Signed-off-by: Mark Wielaard --- libdw/ChangeLog | 4 ++++ libdw/memory-access.h | 5 +++++ src/ChangeLog | 5 +++++ src/readelf.c | 12 ++++++------ 4 files changed, 20 insertions(+), 6 deletions(-) diff --git a/libdw/ChangeLog b/libdw/ChangeLog index 78321654..6492c976 100644 --- a/libdw/ChangeLog +++ b/libdw/ChangeLog @@ -1,3 +1,7 @@ +2018-06-12 Mark Wielaard + + * memory-access.h (read_3ubyte_unaligned_inc): New define. + 2018-06-12 Mark Wielaard * libdw.h (__libdw_dieabbrev): Set die->abbrev to DWARF_END_ABBREV diff --git a/libdw/memory-access.h b/libdw/memory-access.h index 22918cb9..a39ad6d2 100644 --- a/libdw/memory-access.h +++ b/libdw/memory-access.h @@ -362,6 +362,11 @@ read_3ubyte_unaligned (Dwarf *dbg, const unsigned char *p) } +#define read_3ubyte_unaligned_inc(Dbg, Addr) \ + ({ uint32_t t_ = read_2ubyte_unaligned (Dbg, Addr); \ + Addr = (__typeof (Addr)) (((uintptr_t) (Addr)) + 3); \ + t_; }) + #define read_addr_unaligned_inc(Nbytes, Dbg, Addr) \ (assert ((Nbytes) == 4 || (Nbytes) == 8), \ ((Nbytes) == 4 ? read_4ubyte_unaligned_inc (Dbg, Addr) \ diff --git a/src/ChangeLog b/src/ChangeLog index fd45405f..fbbb9acb 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,8 @@ +2018-06-12 Mark Wielaard + + * print_form_data): Don't increase strreadp after use. Do + increase readp for DW_FORM_strx[1234]. + 2018-06-11 Mark Wielaard * readelf.c (print_form_data): Don't reuse readp and readendp when diff --git a/src/readelf.c b/src/readelf.c index f1858971..17d91735 100644 --- a/src/readelf.c +++ b/src/readelf.c @@ -7994,9 +7994,9 @@ print_form_data (Dwarf *dbg, int form, const unsigned char *readp, { Dwarf_Off idx; if (offset_len == 8) - idx = read_8ubyte_unaligned_inc (dbg, strreadp); + idx = read_8ubyte_unaligned (dbg, strreadp); else - idx = read_4ubyte_unaligned_inc (dbg, strreadp); + idx = read_4ubyte_unaligned (dbg, strreadp); data = dbg->sectiondata[IDX_debug_str]; if (data == NULL || idx >= data->d_size @@ -8013,25 +8013,25 @@ print_form_data (Dwarf *dbg, int form, const unsigned char *readp, case DW_FORM_strx1: if (readendp - readp < 1) goto invalid_data; - val = *readp; + val = *readp++; goto strx_val; case DW_FORM_strx2: if (readendp - readp < 2) goto invalid_data; - val = read_2ubyte_unaligned (dbg, readp); + val = read_2ubyte_unaligned_inc (dbg, readp); goto strx_val; case DW_FORM_strx3: if (readendp - readp < 3) goto invalid_data; - val = read_3ubyte_unaligned (dbg, readp); + val = read_3ubyte_unaligned_inc (dbg, readp); goto strx_val; case DW_FORM_strx4: if (readendp - readp < 4) goto invalid_data; - val = read_4ubyte_unaligned (dbg, readp); + val = read_4ubyte_unaligned_inc (dbg, readp); goto strx_val; default: -- 2.17.0