From 59aa9d64df8b3d54feb5fac37566bac13013b729 Mon Sep 17 00:00:00 2001 From: Steffen Jaeckel Date: Mon, 17 Mar 2025 17:00:17 +0100 Subject: [PATCH] Check return values of libgcrypt initialisation. Signed-off-by: Steffen Jaeckel --- src/omemo/crypto.c | 19 ++++++++++++++----- src/omemo/omemo.c | 5 +++-- 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/src/omemo/crypto.c b/src/omemo/crypto.c index 0423d9da..8653b1d1 100644 --- a/src/omemo/crypto.c +++ b/src/omemo/crypto.c @@ -49,16 +49,25 @@ int omemo_crypto_init(void) { if (!gcry_check_version(GCRYPT_VERSION)) { - return -1; + return GPG_ERR_UNKNOWN_VERSION; } - gcry_control(GCRYCTL_SUSPEND_SECMEM_WARN); + gcry_error_t ret; + ret = gcry_control(GCRYCTL_SUSPEND_SECMEM_WARN); + if (ret != 0) + return ret; - gcry_control(GCRYCTL_INIT_SECMEM, 16384, 0); + ret = gcry_control(GCRYCTL_INIT_SECMEM, 16384, 0); + if (ret != 0) + return ret; - gcry_control(GCRYCTL_RESUME_SECMEM_WARN); + ret = gcry_control(GCRYCTL_RESUME_SECMEM_WARN); + if (ret != 0) + return ret; - gcry_control(GCRYCTL_INITIALIZATION_FINISHED, 0); + ret = gcry_control(GCRYCTL_INITIALIZATION_FINISHED, 0); + if (ret != 0) + return ret; /* Ask for a first random buffer to ensure CSPRNG is initialized. * Thus we control the memleak produced by gcrypt initialization and we can diff --git a/src/omemo/omemo.c b/src/omemo/omemo.c index 5b512c19..ac134e28 100644 --- a/src/omemo/omemo.c +++ b/src/omemo/omemo.c @@ -133,8 +133,9 @@ omemo_init(void) prof_add_shutdown_routine(_omemo_close); - if (omemo_crypto_init() != 0) { - cons_show("Error initializing OMEMO crypto: gcry_check_version() failed"); + gcry_error_t crypt_res = omemo_crypto_init(); + if (crypt_res != 0) { + cons_show("Error initializing OMEMO crypto: %s", gcry_strerror(crypt_res)); } pthread_mutexattr_init(&omemo_static_data.attr);