[1/6,gdb/symtab] Fix uninitialized memory in buildsym_compunit::finish_block_internal

Message ID 20230830191336.15885-1-tdevries@suse.de
State Committed
Headers
Series [1/6,gdb/symtab] Fix uninitialized memory in buildsym_compunit::finish_block_internal |

Checks

Context Check Description
linaro-tcwg-bot/tcwg_gdb_check--master-aarch64 fail Patch failed to apply
linaro-tcwg-bot/tcwg_gdb_build--master-arm fail Patch failed to apply
linaro-tcwg-bot/tcwg_gdb_build--master-aarch64 fail Patch failed to apply
linaro-tcwg-bot/tcwg_gdb_check--master-arm fail Patch failed to apply

Commit Message

Tom de Vries Aug. 30, 2023, 7:13 p.m. UTC
  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.

PR symtab/30810
Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=30810
---
 gdb/buildsym.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)


base-commit: 59487af3c8490bc5961d330bc0ef4d5f05ecdc59
  

Comments

Tom Tromey Aug. 30, 2023, 8:15 p.m. UTC | #1
>>>>> "Tom" == Tom de Vries via Gdb-patches <gdb-patches@sourceware.org> writes:

Tom> When running test-case gdb.dwarf2/per-bfd-sharing.exp with target board stabs,
Tom> gdb either segfaults or asserts due to reading uninitialized memory, allocated
Tom> here in buildsym_compunit::finish_block_internal:
Tom> ...
Tom> ftype-> set_fields
Tom> 		((struct field *)
Tom> 		 TYPE_ALLOC (ftype, nparams * sizeof (struct field)));
Tom> ...

Tom> Fix this by using TYPE_ZALLOC instead.

At first I was curious about the history of what changed here, but now I
see that dwarf2_attach_fields_to_type is doing the zalloc thing, so I
think it's just the usual thing where nobody uses or tests non-DWARF
stuff (and why would they) so it wasn't caught in some earlier change.

Approved-By: Tom Tromey <tom@tromey.com>

Tom
  

Patch

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