From f6f2ba34c713b5bc65936af836be24ebc74faf46 Mon Sep 17 00:00:00 2001 From: RincewindsHat <12514511+RincewindsHat@users.noreply.github.com> Date: Sun, 12 Mar 2023 13:58:25 +0100 Subject: Fix hash creation --- lib/utils_base.c | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/lib/utils_base.c b/lib/utils_base.c index 39032cbd..105ff44e 100644 --- a/lib/utils_base.c +++ b/lib/utils_base.c @@ -404,9 +404,15 @@ int mp_translate_state (char *state_text) { char *_np_state_generate_key() { int i; char **argv = this_monitoring_plugin->argv; - unsigned char result[20]; char keyname[41]; char *p=NULL; + + unsigned char *result = malloc(256 * sizeof(unsigned char)); + + if (result == NULL) { + die(STATE_UNKNOWN, _("Failed to allocate memory for hashes: %s"), strerror(errno)); + } + #ifdef USE_OPENSSL /* * This code path is chosen if openssl is available (which should be the most common @@ -421,16 +427,22 @@ char *_np_state_generate_key() { EVP_DigestUpdate(ctx, argv[i], strlen(argv[i])); } - EVP_DigestFinalXOF(ctx, &result, 20); + EVP_DigestFinal(ctx, result, NULL); #else + struct sha256_ctx ctx; for(i=0; iargc; i++) { sha256_process_bytes(argv[i], strlen(argv[i]), &ctx); } - sha256_finish_ctx(&ctx, &result); + sha256_finish_ctx(&ctx, result); #endif // FOUNDOPENSSL + + for (i=0; i<20; ++i) { + sprintf(&keyname[2*i], "%02x", result[i]); + } + keyname[40]='\0'; p = strdup(keyname); -- cgit v1.2.3-74-g34f1