PR26418 UBSAN: cache.c:386 null pointer fwrite
authorAlan Modra <amodra@gmail.com>
Wed, 26 Aug 2020 04:48:53 +0000 (14:18 +0930)
committerAlan Modra <amodra@gmail.com>
Wed, 26 Aug 2020 13:53:44 +0000 (23:23 +0930)
PR 26418
* ecofflink.c (WRITE): Don't write size 0 chunks.

bfd/ChangeLog
bfd/ecofflink.c

index c296f6d89a38f20ee9b90b5b463451c7402fad8e..2fd2321a429a27f4173670ab47b221d80ec80af0 100644 (file)
@@ -1,3 +1,8 @@
+2020-08-26  Alan Modra  <amodra@gmail.com>
+
+       PR 26418
+       * ecofflink.c (WRITE): Don't write size 0 chunks.
+
 2020-08-26  Alan Modra  <amodra@gmail.com>
 
        * bfdio.c (bfd_get_file_size): Don't segv on NULL adata.
index e7b35f670db2900240c5df8da2e6f0aff4230d49..7c9a7aeaa0513c71c731ee3f483515340c89cca8 100644 (file)
@@ -1489,10 +1489,12 @@ bfd_ecoff_write_debug (bfd *abfd,
     return FALSE;
 
 #define WRITE(ptr, count, size, offset) \
-  BFD_ASSERT (symhdr->offset == 0 \
-             || (bfd_vma) bfd_tell (abfd) == symhdr->offset); \
-  if (bfd_bwrite (debug->ptr, (bfd_size_type) size * symhdr->count, abfd)\
-      != size * symhdr->count) \
+  BFD_ASSERT (symhdr->offset == 0                              \
+             || (bfd_vma) bfd_tell (abfd) == symhdr->offset);  \
+  if (size != 0                                                        \
+      && bfd_bwrite (debug->ptr,                               \
+                    (bfd_size_type) size * symhdr->count,      \
+                    abfd) != size * symhdr->count)             \
     return FALSE;
 
   WRITE (line, cbLine, sizeof (unsigned char), cbLineOffset);