Fix the mem_sec "small arena"
authorTodd Short <tshort@akamai.com>
Sun, 21 May 2017 14:21:06 +0000 (10:21 -0400)
committerAndy Polyakov <appro@openssl.org>
Mon, 22 May 2017 09:06:35 +0000 (11:06 +0200)
Fix the small arena test to just check for the symptom of the infinite
loop (i.e. initialized set on failure), rather than the actual infinite
loop. This avoids some valgrind errors.

Reviewed-by: Rich Salz <rsalz@openssl.org>
Reviewed-by: Andy Polyakov <appro@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/3512)

test/secmemtest.c

index cb7d1ec63de142b422ea89e1dd59491b0287bdc6..c7d4fe701f9900da0fbf84ab6e2c0016fe5a97ce 100644 (file)
@@ -68,12 +68,15 @@ static int test_sec_mem(void)
     TEST_ptr_null(OPENSSL_secure_malloc((size_t)-1));
     TEST_true(CRYPTO_secure_malloc_done());
 
     TEST_ptr_null(OPENSSL_secure_malloc((size_t)-1));
     TEST_true(CRYPTO_secure_malloc_done());
 
-    TEST_info("Possible infinite loop: small arena");
-    if (!TEST_false(CRYPTO_secure_malloc_init(16, 16)))
+    /*
+     * If init fails, then initialized should be false, if not, this
+     * could cause an infinite loop secure_malloc, but we don't test it
+     */
+    if (TEST_false(CRYPTO_secure_malloc_init(16, 16)) &&
+        !TEST_false(CRYPTO_secure_malloc_initialized())) {
+        TEST_true(CRYPTO_secure_malloc_done());
         goto end;
         goto end;
-    TEST_false(CRYPTO_secure_malloc_initialized());
-    TEST_ptr_null(OPENSSL_secure_malloc((size_t)-1));
-    TEST_true(CRYPTO_secure_malloc_done());
+    }
 
     /*-
      * There was also a possible infinite loop when the number of
 
     /*-
      * There was also a possible infinite loop when the number of
@@ -105,7 +108,7 @@ static int test_sec_mem(void)
             TEST_true(CRYPTO_secure_malloc_done());
     }
 # endif
             TEST_true(CRYPTO_secure_malloc_done());
     }
 # endif
-    
+
     /* this can complete - it was not really secure */
     testresult = 1;
  end:
     /* this can complete - it was not really secure */
     testresult = 1;
  end: