From: David MacKenzie Date: Mon, 7 Feb 1994 05:17:21 +0000 (+0000) Subject: * elfcode.h (prep_headers, swap_out_syms): Check for NULL return X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=b9d5cdf003384875153bbfdf4ac05ea1b83ec22a;p=binutils-gdb.git * elfcode.h (prep_headers, swap_out_syms): Check for NULL return from bfd_new_strtab. (elf_compute_section_file_positions): Check for false return from swap_out_syms. * linker.c (default_indirect_link_order): Check for NULL return from bfd_get_relocated_section_contents. * syms.c: Make example application in doc call xmalloc, not bfd_xmalloc. * aoutx.h (NAME(aout,slurp_symbol_table), aout_link_get_symbols, NAME(aout,link_hash_table_create)): * bout.c (b_out_slurp_reloc_table, b_out_squirt_out_relocs): * ecoff.c (ecoff_bfd_link_hash_table_create): * ecofflink.c (bfd_ecoff_debug_init): * format.c (bfd_check_format_matches): * linker.c (_bfd_generic_link_hash_table_create): (_bfd_generic_final_link): * reloc16.c (bfd_coff_reloc16_relax_section): (bfd_coff_reloc16_get_relocated_section_contents): * elf32-hppa.c (hppa_elf_build_arg_reloc_stub): * elf32-mips.c (mips_elf_final_link): * elfcode.h (bfd_new_strtab): (bfd_add_2_to_strtab): (elf_slurp_symbol_table): (elf_corefile_note): * libbfd.c (bfd_zmalloc): Use malloc and check the result, instead of bfd_xmalloc. --- diff --git a/bfd/ChangeLog b/bfd/ChangeLog index e379408d3f8..de585aeb6eb 100644 --- a/bfd/ChangeLog +++ b/bfd/ChangeLog @@ -1,3 +1,35 @@ +Sun Feb 6 20:04:10 1994 David J. Mackenzie (djm@thepub.cygnus.com) + + * elfcode.h (prep_headers, swap_out_syms): Check for NULL return + from bfd_new_strtab. + (elf_compute_section_file_positions): Check for false return from + swap_out_syms. + + * linker.c (default_indirect_link_order): Check for NULL return + from bfd_get_relocated_section_contents. + + * syms.c: Make example application in doc call xmalloc, not + bfd_xmalloc. + + * aoutx.h (NAME(aout,slurp_symbol_table), + aout_link_get_symbols, NAME(aout,link_hash_table_create)): + * bout.c (b_out_slurp_reloc_table, b_out_squirt_out_relocs): + * ecoff.c (ecoff_bfd_link_hash_table_create): + * ecofflink.c (bfd_ecoff_debug_init): + * format.c (bfd_check_format_matches): + * linker.c (_bfd_generic_link_hash_table_create): + (_bfd_generic_final_link): + * reloc16.c (bfd_coff_reloc16_relax_section): + (bfd_coff_reloc16_get_relocated_section_contents): + * elf32-hppa.c (hppa_elf_build_arg_reloc_stub): + * elf32-mips.c (mips_elf_final_link): + * elfcode.h (bfd_new_strtab): + (bfd_add_2_to_strtab): + (elf_slurp_symbol_table): + (elf_corefile_note): + * libbfd.c (bfd_zmalloc): + Use malloc and check the result, instead of bfd_xmalloc. + Sat Feb 5 12:39:28 1994 Jim Kingdon (kingdon@lioth.cygnus.com) * config.bfd: Put m68*-*-sysv* line after m68*-*-sysv4*. diff --git a/bfd/elfcode.h b/bfd/elfcode.h index 88f4cc90088..b2b99d34b43 100644 --- a/bfd/elfcode.h +++ b/bfd/elfcode.h @@ -1,5 +1,5 @@ /* ELF executable support for BFD. - Copyright 1991, 1992, 1993 Free Software Foundation, Inc. + Copyright 1991, 1992, 1993, 1994 Free Software Foundation, Inc. Written by Fred Fish @ Cygnus Support, from information published in "UNIX System V Release 4, Programmers Guide: ANSI C and @@ -133,7 +133,7 @@ static int elf_symbol_from_bfd_symbol PARAMS ((bfd *, struct symbol_cache_entry **)); static void elf_map_symbols PARAMS ((bfd *)); -static void swap_out_syms PARAMS ((bfd *)); +static boolean swap_out_syms PARAMS ((bfd *)); #ifdef DEBUG static void elf_debug_section PARAMS ((char *, int, Elf_Internal_Shdr *)); @@ -380,9 +380,18 @@ DEFUN (bfd_new_strtab, (abfd), { struct strtab *ss; - ss = (struct strtab *) bfd_xmalloc (sizeof (struct strtab)); - ss->tab = bfd_xmalloc (1); - BFD_ASSERT (ss->tab != 0); + ss = (struct strtab *) malloc (sizeof (struct strtab)); + if (!ss) + { + bfd_error = no_memory; + return NULL; + } + ss->tab = malloc (1); + if (!ss->tab) + { + bfd_error = no_memory; + return NULL; + } *ss->tab = 0; ss->nentries = 0; ss->length = 1; @@ -426,7 +435,7 @@ DEFUN (bfd_add_2_to_strtab, (abfd, ss, str, str2), if (ss->length) ss->tab = realloc (ss->tab, ss->length + ln); else - ss->tab = bfd_xmalloc (ln); + ss->tab = malloc (ln); BFD_ASSERT (ss->tab != 0); strcpy (ss->tab + ss->length, str); @@ -1485,7 +1494,8 @@ DEFUN (elf_compute_section_file_positions, (abfd), bfd * abfd) bfd_map_over_sections (abfd, fix_up_strtabs, 0); /* .stab/.stabstr &c */ - swap_out_syms (abfd); + if (swap_out_syms (abfd) == false) + return false; assign_file_positions_except_relocs (abfd); @@ -1938,6 +1948,9 @@ prep_headers (abfd) i_shdrp = elf_elfsections (abfd); shstrtab = bfd_new_strtab (abfd); + if (!shstrtab) + return false; + elf_shstrtab (abfd) = shstrtab; i_ehdrp->e_ident[EI_MAG0] = ELFMAG0; @@ -2031,7 +2044,7 @@ prep_headers (abfd) return true; } -static void +static boolean swap_out_syms (abfd) bfd *abfd; { @@ -2047,6 +2060,8 @@ swap_out_syms (abfd) Elf_External_Sym *outbound_syms; int idx; + if (!stt) + return false; symtab_hdr = &elf_tdata (abfd)->symtab_hdr; symtab_hdr->sh_type = SHT_SYMTAB; symtab_hdr->sh_entsize = sizeof (Elf_External_Sym); @@ -2191,6 +2206,7 @@ swap_out_syms (abfd) this_hdr->sh_addralign = 1; this_hdr->size = 0; } + return true; } static boolean @@ -2510,7 +2526,12 @@ DEFUN (elf_slurp_symbol_table, (abfd, symptrs), sym = symbase; /* Temporarily allocate room for the raw ELF symbols. */ - x_symp = (Elf_External_Sym *) bfd_xmalloc (symcount * sizeof (Elf_External_Sym)); + x_symp = (Elf_External_Sym *) malloc (symcount * sizeof (Elf_External_Sym)); + if (!x_symp) + { + bfd_error = no_memory; + return false; + } if (bfd_read ((PTR) x_symp, sizeof (Elf_External_Sym), symcount, abfd) != symcount * sizeof (Elf_External_Sym)) @@ -3349,7 +3370,7 @@ DEFUN (elf_corefile_note, (abfd, hdr), asection *newsect; if (hdr->p_filesz > 0 - && (buf = (char *) bfd_xmalloc (hdr->p_filesz)) != NULL + && (buf = (char *) malloc (hdr->p_filesz)) != NULL && bfd_seek (abfd, hdr->p_offset, SEEK_SET) != -1 && bfd_read ((PTR) buf, hdr->p_filesz, 1, abfd) == hdr->p_filesz) { @@ -3400,6 +3421,11 @@ DEFUN (elf_corefile_note, (abfd, hdr), { free (buf); } + else if (hdr->p_filesz > 0) + { + bfd_error = no_memory; + return false; + } return true; }