aboutsummaryrefslogtreecommitdiff
path: root/bfd/elfcode.h
diff options
context:
space:
mode:
authorAlan Modra <amodra@gmail.com>2019-09-02 16:13:05 +0930
committerAlan Modra <amodra@gmail.com>2019-09-05 11:33:34 +0930
commit89bdc77eabf5ede68322f6e47e003c1dc45b9ccb (patch)
tree87e650254fe116fdf69906ca003a0d8c34c491ac /bfd/elfcode.h
parent809f9153986595498fbb59e547ea4e75a94a50f6 (diff)
downloadgdb-89bdc77eabf5ede68322f6e47e003c1dc45b9ccb.zip
gdb-89bdc77eabf5ede68322f6e47e003c1dc45b9ccb.tar.gz
gdb-89bdc77eabf5ede68322f6e47e003c1dc45b9ccb.tar.bz2
PR24955, libbfd terminating program on out of memory
This patch fixes the worst of the cases where libbfd might terminate a program due to calling xstrdup or xmalloc. I've also fixed some error paths that didn't clean up properly. PR 24955 * libbfd-in.h (bfd_strdup): New inline function. * archive.c (_bfd_get_elt_at_filepos): Use bfd_strdup. Close bfd on error. * elfcode.h (_bfd_elf_bfd_from_remote_memory): Use bfd_strdup. * opncls.c (bfd_fopen): Use bfd_strdup. Close fd and stream on error. (bfd_openstreamr): Use bfd_strdup. (bfd_openr_iovec, bfd_openw, bfd_create): Likewise. * plugin.c (try_load_plugin): Use bfd_malloc. * libbfd.h: Regenerate.
Diffstat (limited to 'bfd/elfcode.h')
-rw-r--r--bfd/elfcode.h11
1 files changed, 10 insertions, 1 deletions
diff --git a/bfd/elfcode.h b/bfd/elfcode.h
index 9a73c3b..625ae99 100644
--- a/bfd/elfcode.h
+++ b/bfd/elfcode.h
@@ -1652,6 +1652,7 @@ NAME(_bfd_elf,bfd_from_remote_memory)
bfd_vma high_offset;
bfd_vma shdr_end;
bfd_vma loadbase;
+ char *filename;
/* Read in the ELF header in external format. */
err = target_read_memory (ehdr_vma, (bfd_byte *) &x_ehdr, sizeof x_ehdr);
@@ -1859,14 +1860,22 @@ NAME(_bfd_elf,bfd_from_remote_memory)
free (contents);
return NULL;
}
+ filename = bfd_strdup ("<in-memory>");
+ if (filename == NULL)
+ {
+ free (bim);
+ free (contents);
+ return NULL;
+ }
nbfd = _bfd_new_bfd ();
if (nbfd == NULL)
{
+ free (filename);
free (bim);
free (contents);
return NULL;
}
- nbfd->filename = xstrdup ("<in-memory>");
+ nbfd->filename = filename;
nbfd->xvec = templ->xvec;
bim->size = high_offset;
bim->buffer = contents;