]> git.ipfire.org Git - thirdparty/elfutils.git/commitdiff
In mixed core notes, don't let handle_core_item repeat.
authorPetr Machata <pmachata@redhat.com>
Wed, 19 Sep 2012 14:52:07 +0000 (16:52 +0200)
committerPetr Machata <pmachata@redhat.com>
Mon, 24 Sep 2012 23:37:29 +0000 (01:37 +0200)
If a core note contains both registers and items, descsz is 0 to express
that we don't wish to repeat the items.  If there is only one item in
such note, a special block of code hits that passes &size to
handle_core_item, which will decrease that size by the amount consumed by
the item.  But because size is 0, it underflows and wraps, and the loop
following this block, which handles the common case, overruns the core
note buffer.

Signed-off-by: Petr Machata <pmachata@redhat.com>
src/readelf.c

index 2954e7427a23605e957cdf20f9e184544c4b172a..5d167ebc711e0e6d854c56cdd03aa1dfa2ceea7f 100644 (file)
@@ -7699,7 +7699,11 @@ handle_core_items (Elf *core, const void *desc, size_t descsz,
   if (nitems == 1)
     {
       size_t size = descsz;
-      colno = handle_core_item (core, sorted_items[0], desc, colno, &size);
+      /* 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;