[prev in list] [next in list] [prev in thread] [next in thread] 

List:       gdb-cvs
Subject:    [binutils-gdb] [gdb/symtab] Fix uninitialized memory in buildsym_compunit::finish_block_internal
From:       Tom de Vries via Gdb-cvs <gdb-cvs () sourceware ! org>
Date:       2023-08-31 7:37:55
Message-ID: 20230831073755.EF1423858C2B () sourceware ! org
[Download RAW message or body]

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

commit 0b8b932dce26ef8e907b3b3c06b01a99420245fe
Author: Tom de Vries <tdevries@suse.de>
Date:   Thu Aug 31 09:37:44 2023 +0200

    [gdb/symtab] Fix uninitialized memory in buildsym_compunit::finish_block_internal
    
    When running test-case gdb.dwarf2/per-bfd-sharing.exp with target board stabs,
    gdb either segfaults or asserts due to reading uninitialized memory, allocated
    here in buildsym_compunit::finish_block_internal:
    ...
                  ftype->set_fields
                    ((struct field *)
                     TYPE_ALLOC (ftype, nparams * sizeof (struct field)));
    ...
    
    Fix this by using TYPE_ZALLOC instead.
    
    Tested on x86_64-linux.
    
    Approved-By: Tom Tromey <tom@tromey.com>
    
    PR symtab/30810
    Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=30810

Diff:
---
 gdb/buildsym.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/gdb/buildsym.c b/gdb/buildsym.c
index 832b689cf03..65ce3a0f5a8 100644
--- a/gdb/buildsym.c
+++ b/gdb/buildsym.c
@@ -267,7 +267,7 @@ buildsym_compunit::finish_block_internal
 	      ftype->set_num_fields (nparams);
 	      ftype->set_fields
 		((struct field *)
-		 TYPE_ALLOC (ftype, nparams * sizeof (struct field)));
+		 TYPE_ZALLOC (ftype, nparams * sizeof (struct field)));
 
 	      iparams = 0;
 	      /* Here we want to directly access the dictionary, because
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic