Avoid creating an illegal pointer
authorKurt Roeckx <kurt@roeckx.be>
Sat, 21 May 2016 14:53:14 +0000 (16:53 +0200)
committerKurt Roeckx <kurt@roeckx.be>
Sun, 22 May 2016 10:05:15 +0000 (12:05 +0200)
Found by tis-interpreter

Reviewed-by: Rich Salz <rsalz@openssl.org>
GH: #1106

crypto/bn/bn_lib.c

index 7c434020de7c1b50feb2f5717aebe26a8e688bad..ccdefb354f4f7a7be8d66b256df258b1b3c7e714 100644 (file)
@@ -1022,9 +1022,11 @@ void bn_correct_top(BIGNUM *a)
     int tmp_top = a->top;
 
     if (tmp_top > 0) {
-        for (ftl = &(a->d[tmp_top - 1]); tmp_top > 0; tmp_top--)
-            if (*(ftl--))
+        for (ftl = &(a->d[tmp_top]); tmp_top > 0; tmp_top--) {
+            ftl--;
+            if (*ftl != 0)
                 break;
+        }
         a->top = tmp_top;
     }
     bn_pollute(a);