aboutsummaryrefslogtreecommitdiff
path: root/bfd/som.c
diff options
context:
space:
mode:
authorAlan Modra <amodra@gmail.com>2020-02-19 13:12:52 +1030
committerAlan Modra <amodra@gmail.com>2020-02-19 13:12:52 +1030
commit96d3b80f5498c0aa40099f37f6384f2041df045f (patch)
treeaf27c606e933b65af33c3fdd2e02cc6ef0dff8c3 /bfd/som.c
parent986f078366b193ed9f5bd02af965f3af958ba859 (diff)
downloadgdb-96d3b80f5498c0aa40099f37f6384f2041df045f.zip
gdb-96d3b80f5498c0aa40099f37f6384f2041df045f.tar.gz
gdb-96d3b80f5498c0aa40099f37f6384f2041df045f.tar.bz2
Check return status of memory alloc functions
This fixes a number of places that call a memory allocation function without checking for a NULL return before using. * mach-o.c (bfd_mach_o_flatten_sections): Return a bfd_boolean, FALSE if memory alloc fails. Adjust calls. * som.c (som_prep_for_fixups): Likewise. * vms-alpha.c (alpha_vms_add_fixup_lp, alpha_vms_add_fixup_ca), (alpha_vms_add_fixup_qr, alpha_vms_add_fixup_lr), (alpha_vms_add_lw_reloc, alpha_vms_add_qw_reloc): Likewise. * som.c (som_build_and_write_symbol_table): Return via error_return on seek failure. * vms-alpha.c (VEC_APPEND): Adjust for vector_grow1 changes. (VEC_APPEND_EL): Delete. (vector_grow1): Return pointer to element. Catch overflow. Return NULL on memory allocation failure. (alpha_vms_add_fixup_lp): Replace VEC_APPEND_EL with VEC_APPEND. (alpha_vms_add_fixup_ca): Likewise. (alpha_vms_link_add_object_symbols): Check VEC_APPEND result before using. * elf.c (bfd_section_from_shdr): Check bfd_zalloc2 result.
Diffstat (limited to 'bfd/som.c')
-rw-r--r--bfd/som.c14
1 files changed, 9 insertions, 5 deletions
diff --git a/bfd/som.c b/bfd/som.c
index cbe970f..9c29230 100644
--- a/bfd/som.c
+++ b/bfd/som.c
@@ -2798,7 +2798,7 @@ compare_subspaces (const void *arg1, const void *arg2)
/* Perform various work in preparation for emitting the fixup stream. */
-static void
+static bfd_boolean
som_prep_for_fixups (bfd *abfd, asymbol **syms, unsigned long num_syms)
{
unsigned long i;
@@ -2876,6 +2876,8 @@ som_prep_for_fixups (bfd *abfd, asymbol **syms, unsigned long num_syms)
/* Sort a copy of the symbol table, rather than the canonical
output symbol table. */
sorted_syms = bfd_zalloc2 (abfd, num_syms, sizeof (asymbol *));
+ if (sorted_syms == NULL)
+ return FALSE;
memcpy (sorted_syms, syms, num_syms * sizeof (asymbol *));
qsort (sorted_syms, num_syms, sizeof (asymbol *), compare_syms);
obj_som_sorted_syms (abfd) = sorted_syms;
@@ -2891,6 +2893,7 @@ som_prep_for_fixups (bfd *abfd, asymbol **syms, unsigned long num_syms)
else
som_symbol_data (sorted_syms[i])->index = i;
}
+ return TRUE;
}
static bfd_boolean
@@ -4009,9 +4012,10 @@ som_finish_writing (bfd *abfd)
current_offset += strings_size;
/* Do prep work before handling fixups. */
- som_prep_for_fixups (abfd,
- bfd_get_outsymbols (abfd),
- bfd_get_symcount (abfd));
+ if (!som_prep_for_fixups (abfd,
+ bfd_get_outsymbols (abfd),
+ bfd_get_symcount (abfd)))
+ return FALSE;
/* At the end of the file is the fixup stream which starts on a
word boundary. */
@@ -4500,7 +4504,7 @@ som_build_and_write_symbol_table (bfd *abfd)
/* Everything is ready, seek to the right location and
scribble out the symbol table. */
if (bfd_seek (abfd, symtab_location, SEEK_SET) != 0)
- return FALSE;
+ goto error_return;
symtab_size = num_syms;
symtab_size *= sizeof (struct som_external_symbol_dictionary_record);