From c823ca1e454570ef1cc1e2fd624f862d4b441055 Mon Sep 17 00:00:00 2001 From: "Todd C. Miller" Date: Tue, 20 Sep 2022 16:13:31 -0600 Subject: [PATCH] Quiet libgcrypt run-time warning about not being initialized. Fixes Debian bug #1019428 and Ubuntu bug #1397663. --- lib/util/digest_gcrypt.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/lib/util/digest_gcrypt.c b/lib/util/digest_gcrypt.c index 3ec715228..075e27227 100644 --- a/lib/util/digest_gcrypt.c +++ b/lib/util/digest_gcrypt.c @@ -23,6 +23,11 @@ #include +#ifdef HAVE_STDBOOL_H +# include +#else +# include "compat/stdbool.h" +#endif #include #include #include @@ -33,6 +38,8 @@ #include "sudo_debug.h" #include "sudo_digest.h" +#define SUDO_LIBGCRYPT_VERSION_MIN "1.3.0" + struct sudo_digest { int gcry_digest_type; unsigned int digest_len; @@ -61,9 +68,21 @@ struct sudo_digest * sudo_digest_alloc_v1(int digest_type) { debug_decl(sudo_digest_alloc, SUDO_DEBUG_UTIL); + static bool initialized = false; struct sudo_digest *dig; int gcry_digest_type; + if (!initialized) { + if (!gcry_check_version(SUDO_LIBGCRYPT_VERSION_MIN)) { + sudo_debug_printf(SUDO_DEBUG_ERROR|SUDO_DEBUG_LINENO, + "libgcrypt too old (need %s, have %s)", + SUDO_LIBGCRYPT_VERSION_MIN, gcry_check_version(NULL)); + debug_return_ptr(NULL); + } + gcry_control(GCRYCTL_INITIALIZATION_FINISHED, 0); + initialized = true; + } + gcry_digest_type = sudo_digest_type_to_gcry(digest_type); if (gcry_digest_type == -1) { errno = EINVAL;