[binutils-gdb] Fix an undefined behaviour in the BFD library's DWARF parser.

Nick Clifton nickc@sourceware.org
Wed Dec 15 17:49:52 GMT 2021


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

commit 4d3605c8ca92bcde848581a8ec031827c798501b
Author: Nikita Popov <npv1310@gmail.com>
Date:   Wed Dec 15 17:49:06 2021 +0000

    Fix an undefined behaviour in the BFD library's DWARF parser.
    
            PR 28687
            * dwarf1.c (parse_die): Fix undefined behaviour in range tests.

Diff:
---
 bfd/ChangeLog | 5 +++++
 bfd/dwarf1.c  | 6 ++----
 2 files changed, 7 insertions(+), 4 deletions(-)

diff --git a/bfd/ChangeLog b/bfd/ChangeLog
index 35b659b4ef9..24311710088 100644
--- a/bfd/ChangeLog
+++ b/bfd/ChangeLog
@@ -1,3 +1,8 @@
+2021-12-15  Nikita Popov  <npv1310@gmail.com>
+
+	PR 28687
+	* dwarf1.c (parse_die): Fix undefined behaviour in range tests.
+
 2021-11-17  Nick Clifton  <nickc@redhat.com>
 
 	PR 28452
diff --git a/bfd/dwarf1.c b/bfd/dwarf1.c
index f1c4e7ec48c..9f4665501b4 100644
--- a/bfd/dwarf1.c
+++ b/bfd/dwarf1.c
@@ -258,8 +258,7 @@ parse_die (bfd *	     abfd,
 	  if (xptr + 2 <= aDiePtrEnd)
 	    {
 	      block_len = bfd_get_16 (abfd, xptr);
-	      if (xptr + block_len > aDiePtrEnd
-		  || xptr + block_len < xptr)
+	      if ((unsigned int) (aDiePtrEnd - xptr) < block_len)
 		return false;
 	      xptr += block_len;
 	    }
@@ -269,8 +268,7 @@ parse_die (bfd *	     abfd,
 	  if (xptr + 4 <= aDiePtrEnd)
 	    {
 	      block_len = bfd_get_32 (abfd, xptr);
-	      if (xptr + block_len > aDiePtrEnd
-		  || xptr + block_len < xptr)
+	      if ((unsigned int) (aDiePtrEnd - xptr) < block_len)
 		return false;
 	      xptr += block_len;
 	    }


More information about the Binutils-cvs mailing list