[v2] ld/pdb: Avoid double-free on malformed symbol data

Message ID 20261002174508.1414-2-oleg.tolmatcev@gmail.com
State New
Headers
Series [v2] ld/pdb: Avoid double-free on malformed symbol data |

Checks

Context Check Description
linaro-tcwg-bot/tcwg_binutils_build--master-arm success Build passed
linaro-tcwg-bot/tcwg_binutils_build--master-aarch64 success Build passed
linaro-tcwg-bot/tcwg_binutils_check--master-aarch64 success Test passed
linaro-tcwg-bot/tcwg_binutils_check--master-arm success Test passed

Commit Message

Oleg Tolmatcev Oct. 2, 2026, 5:45 p.m. UTC
  When handle_debugs_section fails, create_module_info_substream frees
the file arrays for all modules, including the current one.  Do not free
the current array in populate_module_stream as well.

ld/
	* pdb.c (populate_module_stream): Leave mod_source->files cleanup to
	the caller.
---
 ld/pdb.c | 6 +-----
 1 file changed, 1 insertion(+), 5 deletions(-)
  

Comments

Jan Beulich Oct. 5, 2026, 8:13 a.m. UTC | #1
On 02.10.2026 19:45, Oleg Tolmatcev wrote:
> When handle_debugs_section fails, create_module_info_substream frees
> the file arrays for all modules, including the current one.  Do not free
> the current array in populate_module_stream as well.
> 
> ld/
> 	* pdb.c (populate_module_stream): Leave mod_source->files cleanup to
> 	the caller.

Okay.
  

Patch

diff --git a/ld/pdb.c b/ld/pdb.c
index 434bdb197ca..121c5acfe66 100644
--- a/ld/pdb.c
+++ b/ld/pdb.c
@@ -3933,10 +3933,7 @@  populate_module_stream (bfd *stream, bfd *mod, uint32_t *sym_byte_size,
 	    {
 	      if (!handle_debugt_section (s, mod, types, ids, mod_num, strings,
 					  &map, &num_types))
-		{
-		  free (mod_source->files);
-		  return false;
-		}
+		return false;
 
 	      break;
 	    }
@@ -3955,7 +3952,6 @@  populate_module_stream (bfd *stream, bfd *mod, uint32_t *sym_byte_size,
 		{
 		  free (c13_info);
 		  free (syms);
-		  free (mod_source->files);
 		  free (map);
 		  return false;
 		}