+2019-12-30 Alan Modra <amodra@gmail.com>
+
+ * archive.c (do_slurp_bsd_armap): Use bfd_alloc rather than
+ bfd_zalloc when memory is all written after the call.
+ (do_slurp_coff_armap): Likewise. Set bfd_error on ridiculously
+ large allocations that overflow bfd_size_type. Use just one
+ bfd_release on error exit.
+ (_bfd_slurp_extended_name_table): Use bfd_alloc for extended_names,
+ clear last byte rather than the entire array. Use bfd_alloc for
+ string table. Rearrange and simplify code copying file names.
+
2019-12-29 Alan Modra <amodra@gmail.com>
* vms-alpha.c (_bfd_vms_slurp_egsd): Make base_addr a bfd_vma.
if (parsed_size < 4)
return FALSE;
- raw_armap = (bfd_byte *) bfd_zalloc (abfd, parsed_size);
+ raw_armap = (bfd_byte *) bfd_alloc (abfd, parsed_size);
if (raw_armap == NULL)
return FALSE;
bsd-style one in core all at once, for simplicity. */
if (nsymz > ~ (bfd_size_type) 0 / sizeof (carsym))
- return FALSE;
+ {
+ bfd_set_error (bfd_error_no_memory);
+ return FALSE;
+ }
carsym_size = (nsymz * sizeof (carsym));
ptrsize = (4 * nsymz);
if (carsym_size + stringsize + 1 <= carsym_size)
- return FALSE;
+ {
+ bfd_set_error (bfd_error_no_memory);
+ return FALSE;
+ }
- ardata->symdefs = (struct carsym *) bfd_zalloc (abfd,
- carsym_size + stringsize + 1);
+ ardata->symdefs = (struct carsym *) bfd_alloc (abfd,
+ carsym_size + stringsize + 1);
if (ardata->symdefs == NULL)
return FALSE;
carsyms = ardata->symdefs;
{
if (bfd_get_error () != bfd_error_system_call)
bfd_set_error (bfd_error_malformed_archive);
- goto release_raw_armap;
+ goto release_symdefs;
}
/* OK, build the carsyms. */
return TRUE;
-release_raw_armap:
- bfd_release (abfd, raw_armap);
release_symdefs:
bfd_release (abfd, (ardata)->symdefs);
return FALSE;
goto byebye;
bfd_ardata (abfd)->extended_names_size = amt;
- bfd_ardata (abfd)->extended_names = (char *) bfd_zalloc (abfd, amt + 1);
+ bfd_ardata (abfd)->extended_names = (char *) bfd_alloc (abfd, amt + 1);
if (bfd_ardata (abfd)->extended_names == NULL)
{
byebye:
bfd_ardata (abfd)->extended_names = NULL;
goto byebye;
}
+ bfd_ardata (abfd)->extended_names[amt] = 0;
/* Since the archive is supposed to be printable if it contains
text, the entries in the list are newline-padded, not null
if (total_namelen == 0)
return TRUE;
- *tabloc = (char *) bfd_zalloc (abfd, total_namelen);
+ *tabloc = (char *) bfd_alloc (abfd, total_namelen);
if (*tabloc == NULL)
return FALSE;
stroff = last_stroff;
else
{
- strcpy (strptr, normal);
- if (! trailing_slash)
- strptr[thislen] = ARFMAG[1];
- else
- {
- strptr[thislen] = '/';
- strptr[thislen + 1] = ARFMAG[1];
- }
+ last_filename = filename;
stroff = strptr - *tabloc;
last_stroff = stroff;
+ memcpy (strptr, normal, thislen);
+ strptr += thislen;
+ if (trailing_slash)
+ *strptr++ = '/';
+ *strptr++ = ARFMAG[1];
}
hdr->ar_name[0] = ar_padchar (current);
if (bfd_is_thin_archive (abfd) && current->origin > 0)
}
else
_bfd_ar_spacepad (hdr->ar_name + 1, maxname - 1, "%-ld", stroff);
- if (normal != last_filename)
- {
- strptr += thislen + 1;
- if (trailing_slash)
- ++strptr;
- last_filename = filename;
- }
}
}