[tor-commits] [tor/master] Add crypto-initializer functions to those whose return values must be checked

nickm at torproject.org nickm at torproject.org
Thu Nov 26 03:33:56 UTC 2015


commit 10fdee628552bca65ddb86b17e0b057628ad3703
Author: Nick Mathewson <nickm at torproject.org>
Date:   Wed Nov 25 10:36:34 2015 -0500

    Add crypto-initializer functions to those whose return values must be checked
---
 src/common/crypto.c       |    3 ++-
 src/common/crypto.h       |    4 ++--
 src/test/test_workqueue.c |    5 ++++-
 3 files changed, 8 insertions(+), 4 deletions(-)

diff --git a/src/common/crypto.c b/src/common/crypto.c
index b7dc4b8..1ca86ea 100644
--- a/src/common/crypto.c
+++ b/src/common/crypto.c
@@ -322,7 +322,8 @@ int
 crypto_global_init(int useAccel, const char *accelName, const char *accelDir)
 {
   if (!crypto_global_initialized_) {
-    crypto_early_init();
+    if (crypto_early_init() < 0)
+      return -1;
 
     crypto_global_initialized_ = 1;
 
diff --git a/src/common/crypto.h b/src/common/crypto.h
index d2ced63..60f9e28 100644
--- a/src/common/crypto.h
+++ b/src/common/crypto.h
@@ -112,10 +112,10 @@ typedef struct crypto_dh_t crypto_dh_t;
 /* global state */
 const char * crypto_openssl_get_version_str(void);
 const char * crypto_openssl_get_header_version_str(void);
-int crypto_early_init(void);
+int crypto_early_init(void) ATTR_WUR;
 int crypto_global_init(int hardwareAccel,
                        const char *accelName,
-                       const char *accelPath);
+                       const char *accelPath) ATTR_WUR;
 void crypto_thread_cleanup(void);
 int crypto_global_cleanup(void);
 
diff --git a/src/test/test_workqueue.c b/src/test/test_workqueue.c
index 6edfd31..1202f80 100644
--- a/src/test/test_workqueue.c
+++ b/src/test/test_workqueue.c
@@ -390,7 +390,10 @@ main(int argc, char **argv)
 
   init_logging(1);
   network_init();
-  crypto_global_init(1, NULL, NULL);
+  if (crypto_global_init(1, NULL, NULL) < 0) {
+    printf("Couldn't initialize crypto subsystem; exiting.\n");
+    return 1;
+  }
   if (crypto_seed_rng() < 0) {
     printf("Couldn't seed RNG; exiting.\n");
     return 1;





More information about the tor-commits mailing list