bn: catch negative zero as an error
authorGeoff Thorpe <geoff@openssl.org>
Thu, 6 Oct 2016 14:02:38 +0000 (09:02 -0500)
committerRichard Levitte <levitte@openssl.org>
Wed, 1 Feb 2017 01:06:38 +0000 (02:06 +0100)
Change-Id: I5ab72ad0aae9069b47d5b7b7b9e25bd1b7afa251
Signed-off-by: Geoff Thorpe <geoff@openssl.org>
Reviewed-by: Richard Levitte <levitte@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/1672)

crypto/bn/bn_lcl.h

index b5be6fc8148b103087a71fdf0876c33ed7063027..5fb3814554c32127e50a6917cdbb6f7782ef875a 100644 (file)
@@ -177,8 +177,8 @@ int RAND_bytes(unsigned char *buf, int num);
         do { \
                 const BIGNUM *_bnum2 = (a); \
                 if (_bnum2 != NULL) { \
-                        OPENSSL_assert((_bnum2->top == 0) || \
-                                (_bnum2->d[_bnum2->top - 1] != 0)); \
+                        OPENSSL_assert(((_bnum2->top == 0) && !_bnum2->neg) || \
+                                (_bnum2->top && (_bnum2->d[_bnum2->top - 1] != 0))); \
                         bn_pollute(_bnum2); \
                 } \
         } while(0)