From c44cce03fdeaf68f2728d448ee341dae9a334e27 Mon Sep 17 00:00:00 2001 From: Jan Kratochvil Date: Wed, 10 Oct 2012 19:32:05 +0200 Subject: [PATCH] src/ * readelf.c (handle_core_items): Limit special repeated items handling to single-item formats '\n', 'b' and 'B', assert OFFSET 0 there. Signed-off-by: Jan Kratochvil --- src/ChangeLog | 5 +++++ src/readelf.c | 34 ++++++++++++++++++---------------- 2 files changed, 23 insertions(+), 16 deletions(-) diff --git a/src/ChangeLog b/src/ChangeLog index 377c12415..4d000139b 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,8 @@ +2013-01-29 Jan Kratochvil + + * readelf.c (handle_core_items): Limit special repeated items handling + to single-item formats '\n', 'b' and 'B', assert OFFSET 0 there. + 2012-12-18 Mark Wielaard * readelf.c (ELF_INPUT_SECTION): New argp key value. diff --git a/src/readelf.c b/src/readelf.c index 0b4645965..c25610248 100644 --- a/src/readelf.c +++ b/src/readelf.c @@ -7851,6 +7851,24 @@ handle_core_items (Elf *core, const void *desc, size_t descsz, { if (nitems == 0) return 0; + unsigned int colno = 0; + + /* FORMAT '\n' makes sense to be present only as a single item as it + processes all the data of a note. FORMATs 'b' and 'B' have a special case + if present as a single item but they can be also processed with other + items below. */ + if (nitems == 1 && (items[0].format == '\n' || items[0].format == 'b' + || items[0].format == 'B')) + { + assert (items[0].offset == 0); + size_t size = descsz; + colno = handle_core_item (core, items, desc, colno, &size); + /* If SIZE is not zero here there is some remaining data. But we do not + know how to process it anyway. */ + return colno; + } + for (size_t i = 0; i < nitems; ++i) + assert (items[i].format != '\n'); /* Sort to collect the groups together. */ const Ebl_Core_Item *sorted_items[nitems]; @@ -7869,23 +7887,7 @@ handle_core_items (Elf *core, const void *desc, size_t descsz, qsort (groups, ngroups, sizeof groups[0], &compare_core_item_groups); /* Write out all the groups. */ - unsigned int colno = 0; - const void *last = desc; - if (nitems == 1) - { - size_t size = descsz; - /* If this note contains registers as well as items, don't pass - &size to express that we don't wish to repeat. */ - colno = handle_core_item (core, sorted_items[0], desc, colno, - size != 0 ? &size : NULL); - - if (size == 0) - return colno; - desc += descsz - size; - descsz = size; - } - do { for (size_t i = 0; i < ngroups; ++i) -- 2.47.2