public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
* Commit: Add more tests for corrupt DWARF data
@ 2022-12-19 11:13 Nick Clifton
  0 siblings, 0 replies; only message in thread
From: Nick Clifton @ 2022-12-19 11:13 UTC (permalink / raw)
  To: binutils

Hi Guys,

  I am applying the patch below to add a couple more tests to
  binutils/dwarf.c to catch cases of corrupt DWARF information.

Cheers
  Nick

binutils/ChangeLog
2022-12-19  Nick Clifton  <nickc@redhat.com>

	PR 29914
	* dwarf.c (fetch_indexed_value): Fail if the section is not big
	enough to contain a header size field.
	(display_debug_addr): Fail if the computed address size is too big
	or too small.

diff --git a/binutils/dwarf.c b/binutils/dwarf.c
index 03b36afcec0..b792902c496 100644
--- a/binutils/dwarf.c
+++ b/binutils/dwarf.c
@@ -739,6 +739,13 @@ fetch_indexed_value (uint64_t idx,
       return -1;
     }
 
+  if (section->size < 4)
+    {
+      warn (_("Section %s is too small to contain an value indexed from another section!\n"),
+	    section->name);
+      return -1;
+    }
+
   uint32_t pointer_size, bias;
 
   if (byte_get (section->start, 4) == 0xffffffff)
@@ -7770,6 +7777,13 @@ display_debug_addr (struct dwarf_section *section,
       header = end;
       idx = 0;
 
+      if (address_size < 1 || address_size > sizeof (uint64_t))
+	{
+	  warn (_("Corrupt %s section: address size (%x) is wrong"),
+		section->name, address_size);
+	  return 0;
+	}
+
       while ((size_t) (end - entry) >= address_size)
 	{
 	  uint64_t base = byte_get (entry, address_size);


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2022-12-19 11:13 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-12-19 11:13 Commit: Add more tests for corrupt DWARF data Nick Clifton

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).