]> git.ipfire.org Git - thirdparty/zlib-ng.git/commitdiff
Fix that s->prev is not used uninitialized in insert_string_* 115/head
authorMika Lindqvist <postmaster@raasu.org>
Thu, 17 Aug 2017 18:35:15 +0000 (21:35 +0300)
committerHans Kristian Rosbach <hk-github@circlestorm.org>
Thu, 24 Aug 2017 10:35:36 +0000 (12:35 +0200)
arch/aarch64/insert_string_acle.c
arch/arm/insert_string_acle.c
arch/x86/insert_string_sse.c
deflate_p.h

index 985b726cf2d2e07fb520b6a35d6f42eeef34e1ee..419ddff7ccc1941b9848ab66723233a41e31a0b6 100644 (file)
  */
 #ifdef ARM_ACLE_CRC_HASH
 Pos insert_string_acle(deflate_state *const s, const Pos str, unsigned int count) {
-    Pos p, lp;
+    Pos p, lp, ret;
 
     if (unlikely(count == 0)) {
         return s->prev[str & s->w_mask];
     }
 
+    ret = 0;
     lp = str + count - 1; /* last position */
 
     for (p = str; p <= lp; p++) {
@@ -43,8 +44,11 @@ Pos insert_string_acle(deflate_state *const s, const Pos str, unsigned int count
         if (s->head[hm] != p) {
             s->prev[p & s->w_mask] = s->head[hm];
             s->head[hm] = p;
+            if (p == lp) {
+                ret = s->prev[lp & s->w_mask]);
+            }
         }
     }
-    return s->prev[lp & s->w_mask];
+    return ret;
 }
 #endif
index 985b726cf2d2e07fb520b6a35d6f42eeef34e1ee..419ddff7ccc1941b9848ab66723233a41e31a0b6 100644 (file)
  */
 #ifdef ARM_ACLE_CRC_HASH
 Pos insert_string_acle(deflate_state *const s, const Pos str, unsigned int count) {
-    Pos p, lp;
+    Pos p, lp, ret;
 
     if (unlikely(count == 0)) {
         return s->prev[str & s->w_mask];
     }
 
+    ret = 0;
     lp = str + count - 1; /* last position */
 
     for (p = str; p <= lp; p++) {
@@ -43,8 +44,11 @@ Pos insert_string_acle(deflate_state *const s, const Pos str, unsigned int count
         if (s->head[hm] != p) {
             s->prev[p & s->w_mask] = s->head[hm];
             s->head[hm] = p;
+            if (p == lp) {
+                ret = s->prev[lp & s->w_mask]);
+            }
         }
     }
-    return s->prev[lp & s->w_mask];
+    return ret;
 }
 #endif
index 4e303feff1e5a8224a574f78de245a66b9220ec7..8d198e973e9bf71d31ecc11ae1343932050c1c9d 100644 (file)
@@ -42,9 +42,11 @@ ZLIB_INTERNAL Pos insert_string_sse(deflate_state *const s, const Pos str, unsig
         if (s->head[h & s->hash_mask] != str+idx) {
             s->prev[(str+idx) & s->w_mask] = s->head[h & s->hash_mask];
             s->head[h & s->hash_mask] = str+idx;
+            if (idx == count-1) {
+                ret = s->prev[(str+idx) & s->w_mask];
+            }
         }
     }
-    ret = s->prev[(str+count-1) & s->w_mask];
     return ret;
 }
 #endif
index b0d06ad87b5c462bf49cb9851c6849c7c9c6e486..f5e8e4cb7b90ad936241ddbb0f63335e1ca9ead9 100644 (file)
@@ -40,9 +40,11 @@ static inline Pos insert_string_c(deflate_state *const s, const Pos str, unsigne
         if (s->head[s->ins_h] != str+idx) {
             s->prev[(str+idx) & s->w_mask] = s->head[s->ins_h];
             s->head[s->ins_h] = str+idx;
+            if (idx == count-1) {
+                ret = s->prev[(str+idx) & s->w_mask];
+            }
         }
     }
-    ret = s->prev[(str+count-1) & s->w_mask];
     return ret;
 }