[binutils-gdb] Avoid ubsan complaint in BFD
Tom Tromey
tromey@sourceware.org
Mon Jul 23 14:14:00 GMT 2018
https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=01bcaf636ad0b1d5fe44a21917ec900af86072a8
commit 01bcaf636ad0b1d5fe44a21917ec900af86072a8
Author: Tom Tromey <tom@tromey.com>
Date: Sun Jul 15 18:07:40 2018 -0600
Avoid ubsan complaint in BFD
I built gdb with ubsan and ran the test suite.
One complaint was due to bfd_get_elf_phdrs passing NULL to memcpy.
This patch avoids the complaint.
bfd/ChangeLog
2018-07-23 Tom Tromey <tom@tromey.com>
* elf.c (bfd_get_elf_phdrs): Don't call memcpy with size 0.
Diff:
---
bfd/ChangeLog | 4 ++++
bfd/elf.c | 5 +++--
2 files changed, 7 insertions(+), 2 deletions(-)
diff --git a/bfd/ChangeLog b/bfd/ChangeLog
index 5b79a25..19fd9df 100644
--- a/bfd/ChangeLog
+++ b/bfd/ChangeLog
@@ -1,3 +1,7 @@
+2018-07-23 Tom Tromey <tom@tromey.com>
+
+ * elf.c (bfd_get_elf_phdrs): Don't call memcpy with size 0.
+
2018-07-21 Eric Botcazou <ebotcazou@adacore.com>
* elf32-arm.c (elf32_arm_final_link_relocate) <R_ARM_GOT32>: Small
diff --git a/bfd/elf.c b/bfd/elf.c
index 874629d..f721827 100644
--- a/bfd/elf.c
+++ b/bfd/elf.c
@@ -11629,8 +11629,9 @@ bfd_get_elf_phdrs (bfd *abfd, void *phdrs)
}
num_phdrs = elf_elfheader (abfd)->e_phnum;
- memcpy (phdrs, elf_tdata (abfd)->phdr,
- num_phdrs * sizeof (Elf_Internal_Phdr));
+ if (num_phdrs != 0)
+ memcpy (phdrs, elf_tdata (abfd)->phdr,
+ num_phdrs * sizeof (Elf_Internal_Phdr));
return num_phdrs;
}
More information about the Binutils-cvs
mailing list