summaryrefslogtreecommitdiff
path: root/bfd/compress.c
diff options
context:
space:
mode:
authorNick Clifton <nickc@redhat.com>2017-04-26 13:07:49 +0100
committerNick Clifton <nickc@redhat.com>2017-04-26 13:07:49 +0100
commite63d123268f23a4cbc45ee55fb6dbc7d84729da3 (patch)
tree55cf4e0aa0a020e36ad1d2d85c11bb91cdfebe4e /bfd/compress.c
parentc185f580b2b3baf7cee762c8ab31ab6925b9534a (diff)
downloadbinutils-gdb-e63d123268f23a4cbc45ee55fb6dbc7d84729da3.tar.gz
Fix seg-fault attempting to compress a debug section in a corrupt binary.
PR binutils/21431 * compress.c (bfd_init_section_compress_status): Check the return value from bfd_malloc.
Diffstat (limited to 'bfd/compress.c')
-rw-r--r--bfd/compress.c19
1 files changed, 9 insertions, 10 deletions
diff --git a/bfd/compress.c b/bfd/compress.c
index f881c074b85..c854a204fd9 100644
--- a/bfd/compress.c
+++ b/bfd/compress.c
@@ -542,7 +542,6 @@ bfd_init_section_compress_status (bfd *abfd, sec_ptr sec)
{
bfd_size_type uncompressed_size;
bfd_byte *uncompressed_buffer;
- bfd_boolean ret;
/* Error if not opened for read. */
if (abfd->direction != read_direction
@@ -558,18 +557,18 @@ bfd_init_section_compress_status (bfd *abfd, sec_ptr sec)
/* Read in the full section contents and compress it. */
uncompressed_size = sec->size;
uncompressed_buffer = (bfd_byte *) bfd_malloc (uncompressed_size);
+ /* PR 21431 */
+ if (uncompressed_buffer == NULL)
+ return FALSE;
+
if (!bfd_get_section_contents (abfd, sec, uncompressed_buffer,
0, uncompressed_size))
- ret = FALSE;
- else
- {
- uncompressed_size = bfd_compress_section_contents (abfd, sec,
- uncompressed_buffer,
- uncompressed_size);
- ret = uncompressed_size != 0;
- }
+ return FALSE;
- return ret;
+ uncompressed_size = bfd_compress_section_contents (abfd, sec,
+ uncompressed_buffer,
+ uncompressed_size);
+ return uncompressed_size != 0;
}
/*