From: Sebastian Harl Date: Wed, 27 Jul 2016 07:45:48 +0000 (+0200) Subject: network plugin: Don't abort() if gcrypt initialization failed. X-Git-Tag: collectd-5.6.0~3^2~8^2~2 X-Git-Url: https://git.octo.it/?p=collectd.git;a=commitdiff_plain;h=a3000cbe3a12163148a28c818269bbdabda1cf5c;ds=sidebyside network plugin: Don't abort() if gcrypt initialization failed. Instead, report an error and let plugin initialization fail. --- diff --git a/src/network.c b/src/network.c index 45f24369..71eb1f25 100644 --- a/src/network.c +++ b/src/network.c @@ -496,7 +496,7 @@ static int network_dispatch_notification (notification_t *n) /* {{{ */ } /* }}} int network_dispatch_notification */ #if HAVE_LIBGCRYPT -static void network_init_gcrypt (void) /* {{{ */ +static int network_init_gcrypt (void) /* {{{ */ { gcry_error_t err; @@ -504,7 +504,7 @@ static void network_init_gcrypt (void) /* {{{ */ * Because you can't know in a library whether another library has * already initialized the library */ if (gcry_control (GCRYCTL_ANY_INITIALIZATION_P)) - return; + return (0); /* http://www.gnupg.org/documentation/manuals/gcrypt/Multi_002dThreading.html * To ensure thread-safety, it's important to set GCRYCTL_SET_THREAD_CBS @@ -518,7 +518,7 @@ static void network_init_gcrypt (void) /* {{{ */ if (err) { ERROR ("network plugin: gcry_control (GCRYCTL_SET_THREAD_CBS) failed: %s", gcry_strerror (err)); - abort (); + return (-1); } # endif @@ -528,11 +528,12 @@ static void network_init_gcrypt (void) /* {{{ */ if (err) { ERROR ("network plugin: gcry_control (GCRYCTL_INIT_SECMEM) failed: %s", gcry_strerror (err)); - abort (); + return (-1); } gcry_control (GCRYCTL_INITIALIZATION_FINISHED); -} /* }}} void network_init_gcrypt */ + return (0); +} /* }}} int network_init_gcrypt */ static gcry_cipher_hd_t network_get_aes256_cypher (sockent_t *se, /* {{{ */ const void *iv, size_t iv_size, const char *username) @@ -2066,7 +2067,12 @@ static int sockent_init_crypto (sockent_t *se) /* {{{ */ { if (se->data.client.security_level > SECURITY_LEVEL_NONE) { - network_init_gcrypt (); + if (network_init_gcrypt () < 0) + { + ERROR ("network plugin: Cannot configure client socket with " + "security: Failed to initialize crypto library."); + return (-1); + } if ((se->data.client.username == NULL) || (se->data.client.password == NULL)) @@ -2086,7 +2092,12 @@ static int sockent_init_crypto (sockent_t *se) /* {{{ */ { if (se->data.server.security_level > SECURITY_LEVEL_NONE) { - network_init_gcrypt (); + if (network_init_gcrypt () < 0) + { + ERROR ("network plugin: Cannot configure server socket with " + "security: Failed to initialize crypto library."); + return (-1); + } if (se->data.server.auth_file == NULL) { @@ -3519,7 +3530,11 @@ static int network_init (void) have_init = 1; #if HAVE_LIBGCRYPT - network_init_gcrypt (); + if (network_init_gcrypt () < 0) + { + ERROR ("network plugin: Failed to initialize crypto library."); + return (-1); + } #endif if (network_config_stats != 0)