aboutsummaryrefslogtreecommitdiff
path: root/bfd/coff64-rs6000.c
diff options
context:
space:
mode:
authorAlan Modra <amodra@gmail.com>2019-12-19 21:46:01 +1030
committerAlan Modra <amodra@gmail.com>2019-12-19 21:52:47 +1030
commit228c8f4be0c428369ec6b68e25696863d1e62ed7 (patch)
treea69cb8af2acba328adf7cf8e59a5ccfab599b288 /bfd/coff64-rs6000.c
parentf00901886d0acb7a4d4b177a5cabe8bd9ca2307b (diff)
downloadgdb-228c8f4be0c428369ec6b68e25696863d1e62ed7.zip
gdb-228c8f4be0c428369ec6b68e25696863d1e62ed7.tar.gz
gdb-228c8f4be0c428369ec6b68e25696863d1e62ed7.tar.bz2
xcoff slurp_armap bounds checking
"count * 8 >= size" might overflow, "count >= size / 8" doesn't. * coff-rs6000.c (_bfd_xcoff_slurp_armap): Don't overflow when checking symbol count against section size. Guard against strlen running off end of buffer by allocating one more byte and zeroing. * coff64-rs6000.c (xcoff64_slurp_armap): Likewise.
Diffstat (limited to 'bfd/coff64-rs6000.c')
-rw-r--r--bfd/coff64-rs6000.c13
1 files changed, 11 insertions, 2 deletions
diff --git a/bfd/coff64-rs6000.c b/bfd/coff64-rs6000.c
index 091da1f..4db61e5 100644
--- a/bfd/coff64-rs6000.c
+++ b/bfd/coff64-rs6000.c
@@ -1933,18 +1933,27 @@ xcoff64_slurp_armap (bfd *abfd)
return FALSE;
sz = bfd_scan_vma (hdr.size, (const char **) NULL, 10);
+ if (sz == (bfd_size_type) -1)
+ {
+ bfd_set_error (bfd_error_no_memory);
+ return FALSE;
+ }
/* Read in the entire symbol table. */
- contents = (bfd_byte *) bfd_alloc (abfd, sz);
+ contents = (bfd_byte *) bfd_alloc (abfd, sz + 1);
if (contents == NULL)
return FALSE;
if (bfd_bread (contents, sz, abfd) != sz)
return FALSE;
+ /* Ensure strings are NULL terminated so we don't wander off the end
+ of the buffer. */
+ contents[sz] = 0;
+
/* The symbol table starts with an eight byte count. */
c = H_GET_64 (abfd, contents);
- if (c * 8 >= sz)
+ if (c >= sz / 8)
{
bfd_set_error (bfd_error_bad_value);
return FALSE;