apr-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From minf...@apache.org
Subject svn commit: r1836438 - in /apr/apr/trunk: crypto/apr_crypto.c test/testcrypto.c
Date Sun, 22 Jul 2018 13:03:42 GMT
Author: minfrin
Date: Sun Jul 22 13:03:42 2018
New Revision: 1836438

URL: http://svn.apache.org/viewvc?rev=1836438&view=rev
Log:
Make sure we compile in the absence of APU_HAVE_CRYPTO_PRNG. Make sure we don't
segfault if the PRNG does not initialise.

Modified:
    apr/apr/trunk/crypto/apr_crypto.c
    apr/apr/trunk/test/testcrypto.c

Modified: apr/apr/trunk/crypto/apr_crypto.c
URL: http://svn.apache.org/viewvc/apr/apr/trunk/crypto/apr_crypto.c?rev=1836438&r1=1836437&r2=1836438&view=diff
==============================================================================
--- apr/apr/trunk/crypto/apr_crypto.c (original)
+++ apr/apr/trunk/crypto/apr_crypto.c Sun Jul 22 13:03:42 2018
@@ -84,9 +84,11 @@ static apr_status_t apr_crypto_term(void
 
 APR_DECLARE(apr_status_t) apr_crypto_init(apr_pool_t *pool)
 {
-    apr_status_t rv;
     apr_pool_t *rootp;
+#if APU_HAVE_CRYPTO_PRNG
+    apr_status_t rv;
     int flags = 0;
+#endif
 
     if (drivers != NULL) {
         return APR_SUCCESS;
@@ -109,6 +111,7 @@ APR_DECLARE(apr_status_t) apr_crypto_ini
     apr_pool_cleanup_register(rootp, NULL, apr_crypto_term,
                               apr_pool_cleanup_null);
 
+#if APU_HAVE_CRYPTO_PRNG
     /* apr_crypto_prng_init() may already have been called with
      * non-default parameters, so ignore APR_EREINIT.
      */
@@ -119,6 +122,7 @@ APR_DECLARE(apr_status_t) apr_crypto_ini
     if (rv != APR_SUCCESS && rv != APR_EREINIT) {
         return rv;
     }
+#endif
 
     return APR_SUCCESS;
 }

Modified: apr/apr/trunk/test/testcrypto.c
URL: http://svn.apache.org/viewvc/apr/apr/trunk/test/testcrypto.c?rev=1836438&r1=1836437&r2=1836438&view=diff
==============================================================================
--- apr/apr/trunk/test/testcrypto.c (original)
+++ apr/apr/trunk/test/testcrypto.c Sun Jul 22 13:03:42 2018
@@ -1455,6 +1455,7 @@ static void test_crypto_equals(abts_case
     TEST_SCALAR_MATCH(6, p, 0);
 }
 
+#if APU_HAVE_CRYPTO_PRNG
 #if APU_HAVE_OPENSSL
 #include <openssl/obj_mac.h> /* for NID_* */
 #endif
@@ -1523,7 +1524,7 @@ static const unsigned char test_PRNG_kat
 static void test_crypto_prng(abts_case *tc, void *data)
 {
     unsigned char randbytes[128], seed[APR_CRYPTO_PRNG_SEED_SIZE];
-    apr_crypto_prng_t *cprng;
+    apr_crypto_prng_t *cprng = NULL;
     apr_pool_t *pool = NULL;
     apr_status_t rv;
     int i;
@@ -1552,8 +1553,10 @@ static void test_crypto_prng(abts_case *
                         rv == APR_SUCCESS);
         }
 
-        rv = apr_crypto_prng_bytes(cprng, randbytes, 128 - 32);
-        ABTS_ASSERT(tc, "apr_crypto_prng_bytes failed", rv == APR_SUCCESS);
+        if (cprng) {
+            rv = apr_crypto_prng_bytes(cprng, randbytes, 128 - 32);
+            ABTS_ASSERT(tc, "apr_crypto_prng_bytes failed", rv == APR_SUCCESS);
+        }
 
         /* Should match the first time only */
         if (i != 0) {
@@ -1567,8 +1570,10 @@ static void test_crypto_prng(abts_case *
                         memcmp(randbytes, test_PRNG_kat0 + 32, 128 - 32) == 0);
         }
 
-        rv = apr_crypto_prng_destroy(cprng);
-        ABTS_ASSERT(tc, "apr_crypto_prng_destroy failed", rv == APR_SUCCESS);
+        if (cprng) {
+            rv = apr_crypto_prng_destroy(cprng);
+            ABTS_ASSERT(tc, "apr_crypto_prng_destroy failed", rv == APR_SUCCESS);
+        }
     }
 
     apr_pool_destroy(pool);
@@ -1688,6 +1693,7 @@ static void test_crypto_thread_random(ab
     apr_pool_destroy(pool);
 }
 #endif
+#endif
 
 abts_suite *testcrypto(abts_suite *suite)
 {
@@ -1768,6 +1774,7 @@ abts_suite *testcrypto(abts_suite *suite
     abts_run_test(suite, test_crypto_memzero, NULL);
     abts_run_test(suite, test_crypto_equals, NULL);
 
+#if APU_HAVE_CRYPTO_PRNG
     abts_run_test(suite, test_crypto_prng, NULL);
 #if APR_HAS_FORK
     abts_run_test(suite, test_crypto_fork_random, NULL);
@@ -1775,6 +1782,7 @@ abts_suite *testcrypto(abts_suite *suite
 #if APR_HAS_THREADS
     abts_run_test(suite, test_crypto_thread_random, NULL);
 #endif
+#endif
 
     return suite;
 }



Mime
View raw message