diff options
author | Alan Modra <amodra@gmail.com> | 2019-09-02 16:13:05 +0930 |
---|---|---|
committer | Alan Modra <amodra@gmail.com> | 2019-09-05 11:33:34 +0930 |
commit | 89bdc77eabf5ede68322f6e47e003c1dc45b9ccb (patch) | |
tree | 87e650254fe116fdf69906ca003a0d8c34c491ac /bfd/libbfd.h | |
parent | 809f9153986595498fbb59e547ea4e75a94a50f6 (diff) | |
download | fsf-binutils-gdb-89bdc77eabf5ede68322f6e47e003c1dc45b9ccb.zip fsf-binutils-gdb-89bdc77eabf5ede68322f6e47e003c1dc45b9ccb.tar.gz fsf-binutils-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/libbfd.h')
-rw-r--r-- | bfd/libbfd.h | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/bfd/libbfd.h b/bfd/libbfd.h index 13f4c5b..aabe247 100644 --- a/bfd/libbfd.h +++ b/bfd/libbfd.h @@ -128,6 +128,15 @@ extern void *bfd_realloc2 extern void *bfd_zmalloc2 (bfd_size_type, bfd_size_type) ATTRIBUTE_HIDDEN; +static inline char * +bfd_strdup (const char *str) +{ + size_t len = strlen (str) + 1; + char *buf = bfd_malloc (len); + if (buf != NULL) + memcpy (buf, str, len); + return buf; +} /* These routines allocate and free things on the BFD's objalloc. */ extern void *bfd_alloc2 |