[binutils-gdb] LD: Guard `new_afile' result with assertions

Maciej W. Rozycki macro@sourceware.org
Fri Feb 20 17:43:03 GMT 2026


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

commit cbc3248e862d0c8c88fbcd47a338b00c2cbdf65f
Author: Maciej W. Rozycki <macro@redhat.com>
Date:   Fri Feb 20 17:29:50 2026 +0000

    LD: Guard `new_afile' result with assertions
    
    Calls to `new_afile' can in principle return a NULL pointer.  However
    in `lookup_name' we dereference the pointer returned without validating
    it first.  Since it's not supposed to be NULL there except where we have
    hit an internal consistency issue just add an assertion for meaningful
    output rather than just a segfault.
    
    For consistency update `cmdline_load_object_only_section' replacing a
    call to `abort' with the same assertion.

Diff:
---
 ld/ldlang.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/ld/ldlang.c b/ld/ldlang.c
index 9f748f38ed6..ef4715192b4 100644
--- a/ld/ldlang.c
+++ b/ld/ldlang.c
@@ -3025,6 +3025,7 @@ lookup_name (const char *name)
       *stat_ptr->tail = rest;
       if (*tail == NULL)
 	stat_ptr->tail = tail;
+      ASSERT (search != NULL);
     }
 
   /* If we have already added this file, or this file is not real
@@ -11170,8 +11171,7 @@ cmdline_load_object_only_section (const char *name)
   lang_input_statement_type *entry
     = new_afile (name, lang_input_file_is_file_enum, NULL, NULL);
 
-  if (!entry)
-    abort ();
+  ASSERT (entry != NULL);
 
   ldfile_open_file (entry);


More information about the Binutils-cvs mailing list