ee4e72f
From 754137e70cf58a64ad524b704a86b651ba0cde07 Mon Sep 17 00:00:00 2001
ee4e72f
From: Petr Stodulka <pstodulk@redhat.com>
ee4e72f
Date: Wed, 14 Dec 2016 16:30:36 +0100
ee4e72f
Subject: [PATCH] Fix CVE-2016-9844 (rhbz#1404283)
ee4e72f
ee4e72f
Fixes buffer overflow in zipinfo in similar way like fix for
ee4e72f
CVE-2014-9913 provided by upstream.
ee4e72f
---
ee4e72f
 zipinfo.c | 14 +++++++++++++-
ee4e72f
 1 file changed, 13 insertions(+), 1 deletion(-)
ee4e72f
ee4e72f
diff --git a/zipinfo.c b/zipinfo.c
ee4e72f
index c03620e..accca2a 100644
ee4e72f
--- a/zipinfo.c
ee4e72f
+++ b/zipinfo.c
ee4e72f
@@ -1984,7 +1984,19 @@ static int zi_short(__G)   /* return PK-type error code */
ee4e72f
         ush  dnum=(ush)((G.crec.general_purpose_bit_flag>>1) & 3);
ee4e72f
         methbuf[3] = dtype[dnum];
ee4e72f
     } else if (methnum >= NUM_METHODS) {   /* unknown */
ee4e72f
-        sprintf(&methbuf[1], "%03u", G.crec.compression_method);
ee4e72f
+        /* 2016-12-05 SMS.
ee4e72f
+         * https://launchpad.net/bugs/1643750
ee4e72f
+         * Unexpectedly large compression methods overflow
ee4e72f
+         * &methbuf[].  Use the old, three-digit decimal format
ee4e72f
+         * for values which fit.  Otherwise, sacrifice the "u",
ee4e72f
+         * and use four-digit hexadecimal.
ee4e72f
+         */
ee4e72f
+        if (G.crec.compression_method <= 999) {
ee4e72f
+              sprintf( &methbuf[ 1], "%03u", G.crec.compression_method);
ee4e72f
+        } else {
ee4e72f
+              sprintf( &methbuf[ 0], "%04X", G.crec.compression_method);
ee4e72f
+        }
ee4e72f
+
ee4e72f
     }
ee4e72f
 
ee4e72f
     for (k = 0;  k < 15;  ++k)
ee4e72f
-- 
ee4e72f
2.5.5
ee4e72f