From: Alan Modra <amodra@gmail.com>
To: binutils@sourceware.org
Subject: objdump buffer overflow in fetch_indexed_string
Date: Tue, 18 Apr 2023 10:55:05 +0930 [thread overview]
Message-ID: <ZD3xccVokEyi/Cbv@squeak.grove.modra.org> (raw)
PR 30361
* dwarf.c (fetch_indexed_string): Sanity check string index.
diff --git a/binutils/dwarf.c b/binutils/dwarf.c
index 87ce1541d1c..86893c59dc7 100644
--- a/binutils/dwarf.c
+++ b/binutils/dwarf.c
@@ -659,14 +659,13 @@ fetch_indexed_string (uint64_t idx,
return (dwo ? _("<no .debug_str.dwo section>")
: _("<no .debug_str section>"));
- index_offset = idx * offset_size;
-
- if (this_set != NULL)
- index_offset += this_set->section_offsets [DW_SECT_STR_OFFSETS];
-
- index_offset += str_offsets_base;
-
- if (index_offset + offset_size > index_section->size)
+ if (_mul_overflow (idx, offset_size, &index_offset)
+ || (this_set != NULL
+ && ((index_offset += this_set->section_offsets [DW_SECT_STR_OFFSETS])
+ < this_set->section_offsets [DW_SECT_STR_OFFSETS]))
+ || (index_offset += str_offsets_base) < str_offsets_base
+ || index_offset + offset_size < offset_size
+ || index_offset + offset_size > index_section->size)
{
warn (_("string index of %" PRIu64 " converts to an offset of %#" PRIx64
" which is too big for section %s"),
@@ -675,11 +674,6 @@ fetch_indexed_string (uint64_t idx,
return _("<string index too big>");
}
- /* FIXME: If we are being paranoid then we should also check to see if
- IDX references an entry beyond the end of the string table pointed to
- by STR_OFFSETS_BASE. (Since there can be more than one string table
- in a DWARF string section). */
-
str_offset = byte_get (index_section->start + index_offset, offset_size);
str_offset -= str_section->address;
--
Alan Modra
Australia Development Lab, IBM
reply other threads:[~2023-04-18 1:25 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=ZD3xccVokEyi/Cbv@squeak.grove.modra.org \
--to=amodra@gmail.com \
--cc=binutils@sourceware.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).