aboutsummaryrefslogtreecommitdiff
path: root/binutils/objcopy.c
diff options
context:
space:
mode:
authorAlan Modra <amodra@gmail.com>2020-08-26 10:11:38 +0930
committerAlan Modra <amodra@gmail.com>2020-08-26 23:23:43 +0930
commita68aba2da76e802faf2ea887a9d8ff16d3d5959f (patch)
tree34b2deeed54c27a6ab1c3bb4cd0d57c748a17f75 /binutils/objcopy.c
parent4449c81a85eef44b10532032207e8db5858c00ee (diff)
downloadgdb-a68aba2da76e802faf2ea887a9d8ff16d3d5959f.zip
gdb-a68aba2da76e802faf2ea887a9d8ff16d3d5959f.tar.gz
gdb-a68aba2da76e802faf2ea887a9d8ff16d3d5959f.tar.bz2
PR26412 UBSAN: objcopy.c:3026 null pointer fwrite
PR 26412 * objcopy.c (copy_object): Don't fwrite NULL contents.
Diffstat (limited to 'binutils/objcopy.c')
-rw-r--r--binutils/objcopy.c5
1 files changed, 3 insertions, 2 deletions
diff --git a/binutils/objcopy.c b/binutils/objcopy.c
index c5af179..1cbcd17 100644
--- a/binutils/objcopy.c
+++ b/binutils/objcopy.c
@@ -3011,7 +3011,8 @@ copy_object (bfd *ibfd, bfd *obfd, const bfd_arch_info_type *input_arch)
}
bfd_size_type size = bfd_section_size (osec);
- /* Note - we allow the dumping of zero-sized sections. */
+ /* Note - we allow the dumping of zero-sized sections,
+ creating an empty file. */
f = fopen (pdump->filename, FOPEN_WB);
if (f == NULL)
@@ -3023,7 +3024,7 @@ copy_object (bfd *ibfd, bfd *obfd, const bfd_arch_info_type *input_arch)
if (bfd_malloc_and_get_section (ibfd, osec, &contents))
{
- if (fwrite (contents, 1, size, f) != size)
+ if (size != 0 && fwrite (contents, 1, size, f) != size)
{
non_fatal (_("error writing section contents to %s (error: %s)"),
pdump->filename,