/* Now we can get the correct number of symbols. */
abfd->symcount = internal_symhdr->isymMax + internal_symhdr->iextMax;
- if (raw != NULL)
- free (raw);
+ free (raw);
return TRUE;
error_return:
- if (raw != NULL)
- free (raw);
+ free (raw);
return FALSE;
}
amt = external_reloc_size * section->reloc_count;
if (bfd_seek (abfd, section->rel_filepos, SEEK_SET) != 0)
return FALSE;
- external_relocs = _bfd_alloc_and_read (abfd, amt, amt);
+ external_relocs = _bfd_malloc_and_read (abfd, amt, amt);
if (external_relocs == NULL)
return FALSE;
internal_relocs = (arelent *) bfd_alloc (abfd, amt);
if (internal_relocs == NULL)
{
- bfd_release (abfd, external_relocs);
+ free (external_relocs);
return FALSE;
}
(*backend->adjust_reloc_in) (abfd, &intern, rptr);
}
- bfd_release (abfd, external_relocs);
+ free (external_relocs);
section->relocation = internal_relocs;
if (reloc_buff != NULL)
bfd_release (abfd, reloc_buff);
- if (buff != NULL)
- free (buff);
+ free (buff);
return TRUE;
error_return:
if (reloc_buff != NULL)
bfd_release (abfd, reloc_buff);
- if (buff != NULL)
- free (buff);
+ free (buff);
return FALSE;
}
\f
char nextname[17];
unsigned int i;
struct areltdata *mapdata;
- bfd_size_type parsed_size;
+ bfd_size_type parsed_size, stringsize;
char *raw_armap;
struct artdata *ardata;
unsigned int count;
/* Get the name of the first element. */
i = bfd_bread ((void *) nextname, (bfd_size_type) 16, abfd);
if (i == 0)
- return TRUE;
+ return TRUE;
if (i != 16)
- return FALSE;
+ return FALSE;
if (bfd_seek (abfd, (file_ptr) -16, SEEK_CUR) != 0)
return FALSE;
parsed_size = mapdata->parsed_size;
free (mapdata);
- raw_armap = (char *) _bfd_alloc_and_read (abfd, parsed_size, parsed_size);
- if (raw_armap == NULL)
+ if (parsed_size + 1 < 9)
{
- if (bfd_get_error () != bfd_error_system_call)
- bfd_set_error (bfd_error_malformed_archive);
+ bfd_set_error (bfd_error_malformed_archive);
return FALSE;
}
+ raw_armap = (char *) _bfd_alloc_and_read (abfd, parsed_size + 1, parsed_size);
+ if (raw_armap == NULL)
+ return FALSE;
+ raw_armap[parsed_size] = 0;
+
ardata->tdata = (void *) raw_armap;
count = H_GET_32 (abfd, raw_armap);
+ if ((parsed_size - 8) / 8 < count)
+ goto error_malformed;
ardata->symdef_count = 0;
ardata->cache = NULL;
/* This code used to overlay the symdefs over the raw archive data,
but that doesn't work on a 64 bit host. */
stringbase = raw_armap + count * 8 + 8;
+ stringsize = parsed_size - (count * 8 + 8);
#ifdef CHECK_ARMAP_HASH
{
amt *= sizeof (carsym);
symdef_ptr = (carsym *) bfd_alloc (abfd, amt);
if (!symdef_ptr)
- return FALSE;
+ goto error_exit;
ardata->symdefs = symdef_ptr;
if (file_offset == 0)
continue;
name_offset = H_GET_32 (abfd, raw_ptr);
+ if (name_offset > stringsize)
+ goto error_malformed;
symdef_ptr->name = stringbase + name_offset;
symdef_ptr->file_offset = file_offset;
++symdef_ptr;
ardata->first_file_filepos = bfd_tell (abfd);
/* Pad to an even boundary. */
ardata->first_file_filepos += ardata->first_file_filepos % 2;
-
abfd->has_armap = TRUE;
-
return TRUE;
+
+ error_malformed:
+ bfd_set_error (bfd_error_malformed_archive);
+ error_exit:
+ ardata->symdef_count = 0;
+ ardata->symdefs = NULL;
+ ardata->tdata = NULL;
+ bfd_release (abfd, raw_armap);
+ return FALSE;
}
/* Write out an armap. */
complain that the index is out of date. Actually, the Ultrix
linker just checks the archive name; the GNU linker may check the
date. */
- stat (abfd->filename, &statbuf);
+ stat (bfd_get_filename (abfd), &statbuf);
_bfd_ar_spacepad (hdr.ar_date, sizeof (hdr.ar_date), "%ld",
(long) (statbuf.st_mtime + 60));
result = ecoff_link_add_externals (abfd, info, external_ext, ssext);
- if (ssext != NULL)
- free (ssext);
- if (external_ext != NULL)
- free (external_ext);
+ free (ssext);
+ free (external_ext);
return result;
error_return:
- if (ssext != NULL)
- free (ssext);
- if (external_ext != NULL)
- free (external_ext);
+ free (ssext);
+ free (external_ext);
return FALSE;
}
return_something:
if (ecoff_data (input_bfd)->raw_syments == NULL)
{
- if (debug->line != NULL)
- free (debug->line);
- if (debug->external_dnr != NULL)
- free (debug->external_dnr);
- if (debug->external_pdr != NULL)
- free (debug->external_pdr);
- if (debug->external_sym != NULL)
- free (debug->external_sym);
- if (debug->external_opt != NULL)
- free (debug->external_opt);
- if (debug->external_aux != NULL)
- free (debug->external_aux);
- if (debug->ss != NULL)
- free (debug->ss);
- if (debug->external_fdr != NULL)
- free (debug->external_fdr);
- if (debug->external_rfd != NULL)
- free (debug->external_rfd);
+ free (debug->line);
+ free (debug->external_dnr);
+ free (debug->external_pdr);
+ free (debug->external_sym);
+ free (debug->external_opt);
+ free (debug->external_aux);
+ free (debug->ss);
+ free (debug->external_fdr);
+ free (debug->external_rfd);
/* Make sure we don't accidentally follow one of these pointers
into freed memory. */
output_section->reloc_count += input_section->reloc_count;
}
- if (contents != NULL)
- free (contents);
- if (external_relocs != NULL)
- free (external_relocs);
+ free (contents);
+ free (external_relocs);
return TRUE;
error_return:
- if (contents != NULL)
- free (contents);
- if (external_relocs != NULL)
- free (external_relocs);
+ free (contents);
+ free (external_relocs);
return FALSE;
}