From: Roland McGrath Date: Wed, 26 Aug 2009 07:23:01 +0000 (-0700) Subject: libdwfl: Support Linux bzip2 kernel images for automatic decompression. X-Git-Tag: elfutils-0.143~26 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=d6ccdc1a05f27bf0bb5d802ec14f879aa9fe3e98;p=thirdparty%2Felfutils.git libdwfl: Support Linux bzip2 kernel images for automatic decompression. --- diff --git a/NEWS b/NEWS index 4d08e2b34..e0ff9dcc8 100644 --- 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 diff --git a/libdwfl/ChangeLog b/libdwfl/ChangeLog index 129d520f0..c5b8edf32 100644 --- a/libdwfl/ChangeLog +++ b/libdwfl/ChangeLog @@ -1,3 +1,8 @@ +2009-08-26 Roland McGrath + + * gzip.c (mapped_zImage): Limit scan to 32kb. + Make this unconditional, support bzip2 kernel images too. + 2009-08-09 Roland McGrath * dwfl_module_build_id.c: Use new macros for versioned definitions. diff --git a/libdwfl/gzip.c b/libdwfl/gzip.c index 664452541..42352db7c 100644 --- a/libdwfl/gzip.c +++ b/libdwfl/gzip.c @@ -53,7 +53,6 @@ #ifdef BZLIB # define inflate_groks_header true -# define mapped_zImage(...) false # include # define unzip __libdw_bunzip2 # define DWFL_E_ZLIB DWFL_E_BZLIB @@ -74,13 +73,15 @@ # 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.