[OpenWrt-Devel] [RFC 2/7] kexec-tools: add patch for fixing zlib/lzma decompression.
Yousong Zhou
yszhou4tech at gmail.com
Fri Jan 23 08:52:07 EST 2015
Let {zlib,lzma}_decompress_file() return NULL if anything wrong happened
thus to allow other decompression methods have a chance to try.
Signed-off-by: Yousong Zhou <yszhou4tech at gmail.com>
---
.../patches/102-fix-zlib-lzma-decompress.patch | 101 ++++++++++++++++++++
1 file changed, 101 insertions(+)
create mode 100644 package/boot/kexec-tools/patches/102-fix-zlib-lzma-decompress.patch
diff --git a/package/boot/kexec-tools/patches/102-fix-zlib-lzma-decompress.patch b/package/boot/kexec-tools/patches/102-fix-zlib-lzma-decompress.patch
new file mode 100644
index 0000000..d39685e
--- /dev/null
+++ b/package/boot/kexec-tools/patches/102-fix-zlib-lzma-decompress.patch
@@ -0,0 +1,101 @@
+--- a/kexec/lzma.c
++++ b/kexec/lzma.c
+@@ -168,7 +168,8 @@ char *lzma_decompress_file(const char *f
+ }
+ fp = lzopen(filename, "rb");
+ if (fp == 0) {
+- die("Cannot open `%s'\n", filename);
++ fprintf(stderr, "Cannot open `%s'\n", filename);
++ return NULL;
+ }
+ size = 0;
+ allocated = 65536;
+@@ -183,16 +184,25 @@ char *lzma_decompress_file(const char *f
+ if ((errno == EINTR) || (errno == EAGAIN))
+ continue;
+
+- die ("read on %s of %ld bytes failed\n",
+- filename, (allocated - size) + 0UL);
++ fprintf(stderr, "%s: read on %s of %ld bytes failed\n",
++ __func__, filename, (allocated - size) + 0UL);
++ size = 0;
++ break;
+ }
+ size += result;
+ } while(result > 0);
++
+ result = lzclose(fp);
+ if (result != LZMA_OK) {
+- die ("Close of %s failed\n", filename);
++ fprintf(stderr, "%s: Close of %s failed\n", __func__, filename);
++ size = 0;
+ }
++
+ *r_size = size;
++ if (size == 0) {
++ free(buf);
++ return NULL;
++ }
+ return buf;
+ }
+ #else
+--- a/kexec/zlib.c
++++ b/kexec/zlib.c
+@@ -37,6 +37,10 @@ char *zlib_decompress_file(const char *f
+ fprintf(stderr, "Cannot open `%s': %s\n", filename, msg);
+ return NULL;
+ }
++ if (gzdirect(fp)) {
++ fprintf(stderr, "`%s' is not in gzip format: %s\n", filename);
++ return NULL;
++ }
+ size = 0;
+ allocated = 65536;
+ buf = xmalloc(allocated);
+@@ -46,7 +50,7 @@ char *zlib_decompress_file(const char *f
+ buf = xrealloc(buf, allocated);
+ }
+ result = gzread(fp, buf + size, allocated - size);
+- if (result < 0) {
++ if (result <= 0) {
+ if ((errno == EINTR) || (errno == EAGAIN))
+ continue;
+
+@@ -54,20 +58,33 @@ char *zlib_decompress_file(const char *f
+ if (errnum == Z_ERRNO) {
+ msg = strerror(errno);
+ }
+- die ("read on %s of %ld bytes failed: %s\n",
+- filename, (allocated - size) + 0UL, msg);
++ if (errnum != Z_OK) {
++ fprintf(stderr, "%s: read on %s of %ld bytes failed with %d: %s\n",
++ __func__, filename, (allocated - size) + 0UL, errnum, msg);
++ size = 0;
++ break;
++ }
+ }
+ size += result;
+ } while(result > 0);
++
+ result = gzclose(fp);
+ if (result != Z_OK) {
+ msg = gzerror(fp, &errnum);
+ if (errnum == Z_ERRNO) {
+ msg = strerror(errno);
+ }
+- die ("Close of %s failed: %s\n", filename, msg);
++ fprintf(stderr, "%s: Close of %s failed with %d: %s\n",
++ __func__, filename, errnum, msg);
++ size = 0;
+ }
+- *r_size = size;
++
++ *r_size = size;
++ if (size == 0) {
++ free(buf);
++ return NULL;
++ }
++
+ return buf;
+ }
+ #else
--
1.7.10.4
_______________________________________________
openwrt-devel mailing list
openwrt-devel at lists.openwrt.org
https://lists.openwrt.org/cgi-bin/mailman/listinfo/openwrt-devel
More information about the openwrt-devel
mailing list