]> git.ipfire.org Git - thirdparty/elfutils.git/commitdiff
libdwfl: Support Linux bzip2 kernel images for automatic decompression.
authorRoland McGrath <roland@redhat.com>
Wed, 26 Aug 2009 07:23:01 +0000 (00:23 -0700)
committerRoland McGrath <roland@redhat.com>
Wed, 26 Aug 2009 07:23:19 +0000 (00:23 -0700)
NEWS
libdwfl/ChangeLog
libdwfl/gzip.c

diff --git a/NEWS b/NEWS
index 4d08e2b3420e5b6aa64c01a1c49f28b4f010d874..e0ff9dcc866f02619572d5206004d36f0a03e874 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -3,6 +3,8 @@ Version 0.143:
 libdw: Various convenience functions for individual attributes now use
        dwarf_attr_integrate to look up indirect inherited attributes.
 
+libdwfl: Support Linux bzip2 kernel images for automatic decompression.
+
 Version 0.142:
 
 libelf: Add elf_getshdrnum alias for elf_getshnum and elf_getshdrstrndx alias
index 129d520f0752da7dec53505eb99aea4bdd2024f3..c5b8edf323194802c6ff4956ea09b0ce47fd54ac 100644 (file)
@@ -1,3 +1,8 @@
+2009-08-26  Roland McGrath  <roland@redhat.com>
+
+       * gzip.c (mapped_zImage): Limit scan to 32kb.
+       Make this unconditional, support bzip2 kernel images too.
+
 2009-08-09  Roland McGrath  <roland@redhat.com>
 
        * dwfl_module_build_id.c: Use new macros for versioned definitions.
index 6644525416afb8fca0f4c112662c97050e999771..42352db7cb2caf513e09cfee46274ed2e5dd2836 100644 (file)
@@ -53,7 +53,6 @@
 
 #ifdef BZLIB
 # define inflate_groks_header  true
-# define mapped_zImage(...)    false
 # include <bzlib.h>
 # define unzip         __libdw_bunzip2
 # define DWFL_E_ZLIB   DWFL_E_BZLIB
 # define unzip         __libdw_gunzip
 # define MAGIC         "\037\213"
 # define Z(what)       Z_##what
+#endif
 
 /* We can also handle Linux kernel zImage format in a very hackish way.
-   If it looks like one, we actually just scan the image for the gzip
-   magic bytes to figure out where the gzip image starts.  */
+   If it looks like one, we actually just scan the image for the right
+   magic bytes to figure out where the compressed image starts.  */
 
-# define LINUX_MAGIC_OFFSET    514
-# define LINUX_MAGIC           "HdrS"
+#define LINUX_MAGIC_OFFSET     514
+#define LINUX_MAGIC            "HdrS"
+#define LINUX_MAX_SCAN         32768
 
 static bool
 mapped_zImage (off64_t *start_offset, void **mapped, size_t *mapped_size)
@@ -90,8 +91,10 @@ mapped_zImage (off64_t *start_offset, void **mapped, size_t *mapped_size)
       && !memcmp (*mapped + LINUX_MAGIC_OFFSET,
                  LINUX_MAGIC, sizeof LINUX_MAGIC - 1))
     {
-      void *p = memmem (*mapped + pos, *mapped_size - pos,
-                       MAGIC, sizeof MAGIC - 1);
+      size_t scan = *mapped_size - pos;
+      if (scan > LINUX_MAX_SCAN)
+       scan = LINUX_MAX_SCAN;
+      void *p = memmem (*mapped + pos, scan, MAGIC, sizeof MAGIC - 1);
       if (p != NULL)
        {
          *start_offset += p - *mapped;
@@ -102,7 +105,6 @@ mapped_zImage (off64_t *start_offset, void **mapped, size_t *mapped_size)
     }
   return false;
 }
-#endif
 
 /* If this is not a compressed image, return DWFL_E_BADELF.
    If we uncompressed it into *WHOLE, *WHOLE_SIZE, return DWFL_E_NOERROR.