Fix CID 1465213: Integer handling issues (evp_extra_test.c)
authorShane Lontis <shane.lontis@oracle.com>
Mon, 6 Jul 2020 07:35:23 +0000 (17:35 +1000)
committerDmitry Belyavskiy <beldmit@gmail.com>
Wed, 8 Jul 2020 08:19:08 +0000 (11:19 +0300)
Reviewed-by: Dmitry Belyavskiy <beldmit@gmail.com>
(Merged from https://github.com/openssl/openssl/pull/12379)

test/evp_extra_test.c

index 1876bdcf11be84254c1421d16130ac3ec1e66d6a..f31ba31e092763011a5daf57760b0bde1dfac725 100644 (file)
@@ -802,7 +802,7 @@ static int test_privatekey_to_pkcs8(void)
     EVP_PKEY *pkey = NULL;
     BIO *membio = NULL;
     char *membuf = NULL;
-    size_t membuf_len = 0;
+    long membuf_len = 0;
     int ok = 0;
 
     if (!TEST_ptr(membio = BIO_new(BIO_s_mem()))
@@ -810,9 +810,9 @@ static int test_privatekey_to_pkcs8(void)
         || !TEST_int_gt(i2d_PKCS8PrivateKey_bio(membio, pkey, NULL,
                                                 NULL, 0, NULL, NULL),
                         0)
-        || !TEST_ptr((membuf_len = (size_t)BIO_get_mem_data(membio, &membuf),
-                      membuf))
-        || !TEST_mem_eq(membuf, membuf_len,
+        || !TEST_int_gt(membuf_len = BIO_get_mem_data(membio, &membuf), 0)
+        || !TEST_ptr(membuf)
+        || !TEST_mem_eq(membuf, (size_t)membuf_len,
                         kExampleRSAKeyPKCS8, sizeof(kExampleRSAKeyPKCS8))
         /*
          * We try to write PEM as well, just to see that it doesn't err, but