X-Git-Url: https://git.libre-soc.org/?a=blobdiff_plain;f=bfd%2Fsom.c;h=d53a3b90b0244fa703955045489144d1190cd2df;hb=13835d88dc51497b9bd68dc1f394ca0de099a380;hp=5719b202c35270789e4ba737b59512c5e37115dd;hpb=0a1b45a20eaa98d4d9026dc1fd17e79e741183af;p=binutils-gdb.git diff --git a/bfd/som.c b/bfd/som.c index 5719b202c35..d53a3b90b02 100644 --- a/bfd/som.c +++ b/bfd/som.c @@ -1,5 +1,5 @@ /* bfd back-end for HP PA-RISC SOM objects. - Copyright (C) 1990-2021 Free Software Foundation, Inc. + Copyright (C) 1990-2022 Free Software Foundation, Inc. Contributed by the Center for Software Science at the University of Utah. @@ -22,7 +22,6 @@ 02110-1301, USA. */ #include "sysdep.h" -#include "alloca-conf.h" #include "bfd.h" #include "libiberty.h" #include "libbfd.h" @@ -4577,9 +4576,11 @@ som_slurp_string_table (bfd *abfd) if (bfd_seek (abfd, obj_som_str_filepos (abfd), SEEK_SET) != 0) return false; amt = obj_som_stringtab_size (abfd); - stringtab = (char *) _bfd_malloc_and_read (abfd, amt, amt); + stringtab = (char *) _bfd_malloc_and_read (abfd, amt + 1, amt); if (stringtab == NULL) return false; + /* Make sure that the strings are zero-terminated. */ + stringtab[amt] = 0; /* Save our results and return success. */ obj_som_stringtab (abfd) = stringtab; @@ -4698,6 +4699,7 @@ som_slurp_symbol_table (bfd *abfd) (flags >> SOM_SYMBOL_TYPE_SH) & SOM_SYMBOL_TYPE_MASK; unsigned int symbol_scope = (flags >> SOM_SYMBOL_SCOPE_SH) & SOM_SYMBOL_SCOPE_MASK; + bfd_vma offset; /* I don't think we care about these. */ if (symbol_type == ST_SYM_EXT || symbol_type == ST_ARG_EXT) @@ -4729,9 +4731,16 @@ som_slurp_symbol_table (bfd *abfd) /* Some reasonable defaults. */ sym->symbol.the_bfd = abfd; - sym->symbol.name = bfd_getb32 (bufp->name) + stringtab; + offset = bfd_getb32 (bufp->name); + if (offset < obj_som_stringtab_size (abfd)) + sym->symbol.name = offset + stringtab; + else + { + bfd_set_error (bfd_error_bad_value); + goto error_return; + } sym->symbol.value = bfd_getb32 (bufp->symbol_value); - sym->symbol.section = 0; + sym->symbol.section = NULL; sym->symbol.flags = 0; switch (symbol_type) @@ -4791,12 +4800,15 @@ som_slurp_symbol_table (bfd *abfd) sym->symbol.section = bfd_section_from_som_symbol (abfd, bufp); sym->symbol.value -= sym->symbol.section->vma; break; + + default: + sym->symbol.section = bfd_und_section_ptr; + break; } /* Check for a weak symbol. */ if (flags & SOM_SYMBOL_SECONDARY_DEF) sym->symbol.flags |= BSF_WEAK; - /* Mark section symbols and symbols used by the debugger. Note $START$ is a magic code symbol, NOT a section symbol. */ if (sym->symbol.name[0] == '$' @@ -4810,7 +4822,6 @@ som_slurp_symbol_table (bfd *abfd) } else if (startswith (sym->symbol.name, "L$0\001")) sym->symbol.flags |= BSF_DEBUGGING; - /* Note increment at bottom of loop, since we skip some symbols we can not include it as part of the for statement. */ sym++; @@ -5841,6 +5852,11 @@ som_decode_symclass (asymbol *symbol) { char c; + /* If the symbol did not have a scope specified, + then it will not have associated section. */ + if (symbol == NULL || symbol->section == NULL) + return '?'; + if (bfd_is_com_section (symbol->section)) return 'C'; if (bfd_is_und_section (symbol->section))