public inbox for binutils-cvs@sourceware.org
help / color / mirror / Atom feed
* [binutils-gdb] asan: heap buffer overflow in dwarf2_directive_filename
@ 2022-06-02  9:05 Alan Modra
  0 siblings, 0 replies; only message in thread
From: Alan Modra @ 2022-06-02  9:05 UTC (permalink / raw)
  To: bfd-cvs

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

commit 6f87d3fd27417e5adb2aa6f106a614296425df57
Author: Alan Modra <amodra@gmail.com>
Date:   Wed Jun 1 17:44:41 2022 +0930

    asan: heap buffer overflow in dwarf2_directive_filename
    
    Seen with .file 4294967289 "xxx.c"
    
            * dwarf2dbg.c (assign_file_to_slot): Catch more cases of integer
            overflow.  Make param i an unsigned int.

Diff:
---
 gas/dwarf2dbg.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/gas/dwarf2dbg.c b/gas/dwarf2dbg.c
index 185d57c253f..b4b252970c1 100644
--- a/gas/dwarf2dbg.c
+++ b/gas/dwarf2dbg.c
@@ -679,7 +679,7 @@ get_directory_table_entry (const char *dirname,
 }
 
 static bool
-assign_file_to_slot (unsigned long i, const char *file, unsigned int dir)
+assign_file_to_slot (unsigned int i, const char *file, unsigned int dir)
 {
   if (i >= files_allocated)
     {
@@ -687,9 +687,11 @@ assign_file_to_slot (unsigned long i, const char *file, unsigned int dir)
 
       files_allocated = i + 32;
       /* Catch wraparound.  */
-      if (files_allocated <= old)
+      if (files_allocated < old
+	  || files_allocated < i
+	  || files_allocated > UINT_MAX / sizeof (struct file_entry))
 	{
-	  as_bad (_("file number %lu is too big"), (unsigned long) i);
+	  as_bad (_("file number %u is too big"), i);
 	  return false;
 	}


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

only message in thread, other threads:[~2022-06-02  9:05 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-06-02  9:05 [binutils-gdb] asan: heap buffer overflow in dwarf2_directive_filename Alan Modra

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