This is the mail archive of the
elfutils-devel@sourceware.org
mailing list for the elfutils project.
[PATCH] readelf: handle_core_item make sure variable length array isn't zero size.
- From: Mark Wielaard <mjw at redhat dot com>
- To: elfutils-devel at lists dot fedorahosted dot org
- Date: Tue, 22 Apr 2014 23:59:08 +0200
- Subject: [PATCH] readelf: handle_core_item make sure variable length array isn't zero size.
The printed array should have at least space for the terminating zero char.
Found by gcc -fsanitize=undefined while running run-readelf-vmcoreinfo.sh.
runtime error: variable length array bound evaluates to non-positive value 0
Signed-off-by: Mark Wielaard <mjw@redhat.com>
---
src/ChangeLog | 5 +++++
src/readelf.c | 2 +-
2 files changed, 6 insertions(+), 1 deletions(-)
diff --git a/src/ChangeLog b/src/ChangeLog
index 874e255..28e52f9 100644
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,5 +1,10 @@
2014-04-22 Mark Wielaard <mjw@redhat.com>
+ * readelf.c (handle_core_item): Make sure variable length array
+ contains at least enough space for terminating zero char.
+
+2014-04-22 Mark Wielaard <mjw@redhat.com>
+
* readelf.c (print_gdb_index_section): Use unsigned int for 31 bits
left shift.
diff --git a/src/readelf.c b/src/readelf.c
index da1bf73..697a361 100644
--- a/src/readelf.c
+++ b/src/readelf.c
@@ -8128,7 +8128,7 @@ handle_core_item (Elf *core, const Ebl_Core_Item *item, const void *desc,
const unsigned int bias = item->format == 'b';
{
- char printed[(negate ? nbits - pop : pop) * 16];
+ char printed[(negate ? nbits - pop : pop) * 16 + 1];
char *p = printed;
*p = '\0';
--
1.7.1