From patchwork Fri Jan 23 13:52:07 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yousong Zhou X-Patchwork-Id: 432168 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from arrakis.dune.hu (arrakis.dune.hu [78.24.191.176]) (using TLSv1.1 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 6CB751402A0 for ; Sat, 24 Jan 2015 01:03:57 +1100 (AEDT) Received: from arrakis.dune.hu (localhost [127.0.0.1]) by arrakis.dune.hu (Postfix) with ESMTP id 6C82428BE3D; Fri, 23 Jan 2015 15:00:59 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on arrakis.dune.hu X-Spam-Level: X-Spam-Status: No, score=-1.5 required=5.0 tests=BAYES_00,FREEMAIL_FROM, T_DKIM_INVALID autolearn=unavailable version=3.3.2 Received: from arrakis.dune.hu (localhost [127.0.0.1]) by arrakis.dune.hu (Postfix) with ESMTP id 909B128BE28 for ; Fri, 23 Jan 2015 15:00:38 +0100 (CET) X-policyd-weight: using cached result; rate: -8.5 Received: from mail-pa0-f49.google.com (mail-pa0-f49.google.com [209.85.220.49]) by arrakis.dune.hu (Postfix) with ESMTPS for ; Fri, 23 Jan 2015 15:00:28 +0100 (CET) Received: by mail-pa0-f49.google.com with SMTP id fa1so8782303pad.8 for ; Fri, 23 Jan 2015 06:02:49 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=NkgjW4BFgBzmbBG8VgjrKGIiYm7/rKPDDhQ/z1+G4ME=; b=H/evookKMBnXeYPqwDQsdVx67fbzoP/X2WwRO7xPl9X2kNoEd27fXcpCWY1/8W/dcw P9CWi/LCjf305ZhCfXAwsEWML17+IhS6AtLaiQchxONEkZVbqD5BnIXK1ORqoNXnSw/k AaCHIWc42UoZz2brqJ4SNyv3KSOgdKmqulCWMWhCpJ9p9L9ZfWdp82tSFRJk+PwUSLX3 a3Pve30N9kclFDIHUX4QMcw4vbB1b98bMveNze3T6wrWtY72SArqsvFeNXRK93uImHE2 lAqmfZqcosExdWL/6w4jEfQU/MIIrahGJFZD4rqgdDE8/zUpY9lwL1JqKrWqUOwhILAb n/jw== X-Received: by 10.66.100.202 with SMTP id fa10mr11671058pab.36.1422021769390; Fri, 23 Jan 2015 06:02:49 -0800 (PST) Received: from debian.corp.sankuai.com ([103.29.140.56]) by mx.google.com with ESMTPSA id pb6sm1459568pdb.93.2015.01.23.06.02.46 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 23 Jan 2015 06:02:48 -0800 (PST) From: Yousong Zhou To: blogic@openwrt.org Date: Fri, 23 Jan 2015 21:52:07 +0800 Message-Id: <1422021132-24526-3-git-send-email-yszhou4tech@gmail.com> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <1422021132-24526-1-git-send-email-yszhou4tech@gmail.com> References: <1422021132-24526-1-git-send-email-yszhou4tech@gmail.com> Cc: openwrt-devel@lists.openwrt.org Subject: [OpenWrt-Devel] [RFC 2/7] kexec-tools: add patch for fixing zlib/lzma decompression. X-BeenThere: openwrt-devel@lists.openwrt.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: OpenWrt Development List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: openwrt-devel-bounces@lists.openwrt.org Sender: "openwrt-devel" 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 --- .../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