From nobody Mon Mar 20 13:33:44 2023 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4PgG0S3nBbz40kLT; Mon, 20 Mar 2023 13:33:44 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4PgG0S32GTz3Nfr; Mon, 20 Mar 2023 13:33:44 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1679319224; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=SueeHq1V9VhyU/kIvgdLEqa2UlvD+twVhnY+nvrh66A=; b=EUqXbI20HWIlF+Jfkzi8lIVAZhOQbB+soGsKiLsDPvlRDKAcwkKzgS2IDeAlYZMQMY4AGb 4VhvBRxBkBu9KA0lbDIvQE5LSca0M2Gk4lCm0yDJ2hPWImJFlTBM1LQOb0+qvF86OX3+RB rb5n31O/hMNaGSl1dDNpG/OFp7d/5WmYTqzKjhQqmDD175L2YI8mXmtviq5otHxjKkOcje 9G0rcS0+TbJht7JjqzdOS11G5s8PO4vVTnVTT4mCtDo/vKJmbybj3VKwTQWDG5SV6VaZ15 h9d5r3JORHD/t2JnIgpwyoj+AvGi/iOUzSECHz+9S7cdZbGKI5vbQ/xaIqekaA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1679319224; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=SueeHq1V9VhyU/kIvgdLEqa2UlvD+twVhnY+nvrh66A=; b=cR4smShlgHzD+hBU4lmJ8isY6SxFKEoZ3cdGFj+GsUhYO++KgweKSfCXALXhxFsPUw3I5S g6Jev81a6w+g8cSRFbZzEC8cIOZDT5rCE1yLuE4RfqKDgQkJHFpgdBURhyM1BAw5/KAoLn pcU6jOktQITOYSu9hfJIcEUr7XFTFBZi6V1OQeHDh3e0Gc76PSSbCQ40dIK14qHztRQoUb lPiBLTR/QmQ/9A/1XE3v2+aZcycSYz8hrajXwHd0hQkd6mRwT3QdqL+6A5R5lWA0jF7sN+ yrbppc7Zx+x0v2SnQB30XHgifDyp+z4Ldnykha2Hv5O+kN9+tyVJQvk4E/TdUg== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1679319224; a=rsa-sha256; cv=none; b=n76uQn23UoQ+/A/M30Sj30zYjBCtP2Dt8UzxOiw2vekH9Gl0yH+YgHHIwtO6ASx+UfJRpI 86r1shO8LpJwGl6cf9XV57bnbrYvA1Al/Ev/HERl5zDDfIXFq3/PToWYHUgY+gYRk2eQ77 3v2vH51znm7QQZQ8kmLIseRRE1hep/AWa03+7Xeon5B+xhi5JeAKYPBsk5yas/rYlFvKVq i+aY72YUb9SYCz0Q1Ky3YbP1ge9cnMC9vVetLlxFxXiN5LXobw2p232sbsUsePJsrF4V5N 06eaBwaANT5997Ba84tbd+S/VSWm//Jhgcln9dy40Ja9Vwql8IJlm1G1LJ2i7Q== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4PgG0S22SmzXWk; Mon, 20 Mar 2023 13:33:44 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 32KDXit2073615; Mon, 20 Mar 2023 13:33:44 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 32KDXiYT073614; Mon, 20 Mar 2023 13:33:44 GMT (envelope-from git) Date: Mon, 20 Mar 2023 13:33:44 GMT Message-Id: <202303201333.32KDXiYT073614@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Mark Johnston Subject: git: 440dbf8a4b7a - stable/13 - readelf: fix -wR option, memory leaks, and -wf minor bug List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: markj X-Git-Repository: src X-Git-Refname: refs/heads/stable/13 X-Git-Reftype: branch X-Git-Commit: 440dbf8a4b7a983e3b93f5e357700093117b6b32 Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch stable/13 has been updated by markj: URL: https://cgit.FreeBSD.org/src/commit/?id=440dbf8a4b7a983e3b93f5e357700093117b6b32 commit 440dbf8a4b7a983e3b93f5e357700093117b6b32 Author: Christos Margiolis AuthorDate: 2023-03-06 17:50:13 +0000 Commit: Mark Johnston CommitDate: 2023-03-20 12:52:57 +0000 readelf: fix -wR option, memory leaks, and -wf minor bug Reviewed by: markj MFC after: 2 weeks Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D38419 (cherry picked from commit cec2d0b1c7ac3196613813c0b07a2387916a8ccd) --- contrib/elftoolchain/readelf/readelf.c | 39 ++++++++++++++++++++++------------ 1 file changed, 25 insertions(+), 14 deletions(-) diff --git a/contrib/elftoolchain/readelf/readelf.c b/contrib/elftoolchain/readelf/readelf.c index 77125b77ebef..daaa7bf62dff 100644 --- a/contrib/elftoolchain/readelf/readelf.c +++ b/contrib/elftoolchain/readelf/readelf.c @@ -4938,8 +4938,10 @@ dump_dwarf_line(struct readelf *re) return; } if (dwarf_attrval_unsigned(die, DW_AT_stmt_list, &offset, - &de) != DW_DLV_OK) + &de) != DW_DLV_OK) { + dwarf_dealloc(re->dbg, die, DW_DLA_DIE); continue; + } length = re->dw_read(d, &offset, 4); if (length == 0xffffffff) { @@ -4950,6 +4952,7 @@ dump_dwarf_line(struct readelf *re) if (length > d->d_size - offset) { warnx("invalid .dwarf_line section"); + dwarf_dealloc(re->dbg, die, DW_DLA_DIE); continue; } @@ -5147,9 +5150,8 @@ dump_dwarf_line(struct readelf *re) (uintmax_t) line); p++; } - - } + dwarf_dealloc(re->dbg, die, DW_DLA_DIE); } if (ret == DW_DLV_ERROR) warnx("dwarf_next_cu_header: %s", dwarf_errmsg(de)); @@ -5192,9 +5194,9 @@ dump_dwarf_line_decoded(struct readelf *re) printf("%-37s %11s %s\n", "Filename", "Line Number", "Starting Address"); if (dwarf_srclines(die, &linebuf, &linecount, &de) != DW_DLV_OK) - continue; + goto done; if (dwarf_srcfiles(die, &srcfiles, &srccount, &de) != DW_DLV_OK) - continue; + goto done; for (i = 0; i < linecount; i++) { ln = linebuf[i]; if (dwarf_line_srcfileno(ln, &fn, &de) != DW_DLV_OK) @@ -5208,6 +5210,8 @@ dump_dwarf_line_decoded(struct readelf *re) (uintmax_t) lineaddr); } putchar('\n'); +done: + dwarf_dealloc(re->dbg, die, DW_DLA_DIE); } } @@ -5840,7 +5844,8 @@ dump_dwarf_ranges_foreach(struct readelf *re, Dwarf_Die die, Dwarf_Addr base) Dwarf_Addr base0; Dwarf_Half attr; Dwarf_Signed attr_count, cnt; - Dwarf_Unsigned off, bytecnt; + Dwarf_Unsigned bytecnt; + Dwarf_Off off; int i, j, ret; if ((ret = dwarf_attrlist(die, &attr_list, &attr_count, &de)) != @@ -5857,11 +5862,12 @@ dump_dwarf_ranges_foreach(struct readelf *re, Dwarf_Die die, Dwarf_Addr base) } if (attr != DW_AT_ranges) continue; - if (dwarf_formudata(attr_list[i], &off, &de) != DW_DLV_OK) { - warnx("dwarf_formudata failed: %s", dwarf_errmsg(de)); + if (dwarf_global_formref(attr_list[i], &off, &de) != DW_DLV_OK) { + warnx("dwarf_global_formref failed: %s", + dwarf_errmsg(de)); continue; } - if (dwarf_get_ranges(re->dbg, (Dwarf_Off) off, &ranges, &cnt, + if (dwarf_get_ranges(re->dbg, off, &ranges, &cnt, &bytecnt, &de) != DW_DLV_OK) continue; base0 = base; @@ -5900,6 +5906,8 @@ cont_search: warnx("dwarf_siblingof: %s", dwarf_errmsg(de)); else if (ret == DW_DLV_OK) dump_dwarf_ranges_foreach(re, ret_die, base); + + dwarf_dealloc(re->dbg, die, DW_DLA_DIE); } static void @@ -6204,7 +6212,7 @@ dump_dwarf_frame_section(struct readelf *re, struct section *s, int alt) Dwarf_Small cie_version; Dwarf_Ptr fde_addr, fde_inst, cie_inst; char *cie_aug, c; - int i, eh_frame; + int i, ret, eh_frame; Dwarf_Error de; printf("\nThe section %s contains:\n\n", s->name); @@ -6219,10 +6227,13 @@ dump_dwarf_frame_section(struct readelf *re, struct section *s, int alt) } } else if (!strcmp(s->name, ".eh_frame")) { eh_frame = 1; - if (dwarf_get_fde_list_eh(re->dbg, &cie_list, &cie_count, - &fde_list, &fde_count, &de) != DW_DLV_OK) { - warnx("dwarf_get_fde_list_eh failed: %s", - dwarf_errmsg(de)); + ret = dwarf_get_fde_list_eh(re->dbg, &cie_list, &cie_count, + &fde_list, &fde_count, &de); + if (ret != DW_DLV_OK) { + if (ret == DW_DLV_ERROR) { + warnx("dwarf_get_fde_list_eh failed: %s", + dwarf_errmsg(de)); + } return; } } else