[binutils-gdb] oss-fuzz: vms-alpha segfault in image_write_section

Alan Modra via Binutils-cvs <[email protected]> Sat, 13 Jun 2026 06:49:27 +0000 (GMT)
Newsgroups gmane.comp.gnu.binutils.cvs
Message-ID <[email protected]>
https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=95451ea43a7e2e4aa806ee7405e9167b2ee653c1

commit 95451ea43a7e2e4aa806ee7405e9167b2ee653c1
Author: Alan Modra <[email protected]>
Date:   Sat Jun 13 10:27:22 2026 +0930

    oss-fuzz: vms-alpha segfault in image_write_section
    
    Yet another case where a fuzzed object file triggers a crash in the
    vms-alpha support.
    
            * vms-alpha.c (image_write_section): Don't segfault on NULL
            image_section.

Diff:
---
 bfd/vms-alpha.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/bfd/vms-alpha.c b/bfd/vms-alpha.c
index 8454ab6ebdc..24b05f90bea 100644
--- a/bfd/vms-alpha.c
+++ b/bfd/vms-alpha.c
@@ -1603,7 +1603,8 @@ image_write_section (bfd *abfd)
 {
   asection *sec = PRIV (image_section);
 
-  if ((sec->flags & SEC_IN_MEMORY) != 0 && sec->contents == NULL)
+  if (sec == NULL
+      || ((sec->flags & SEC_IN_MEMORY) != 0 && sec->contents == NULL))
     return NULL;
   return sec;
 }