summaryrefslogtreecommitdiffstats
path: root/lib/utils_base.c
diff options
context:
space:
mode:
authorRincewindsHat <12514511+RincewindsHat@users.noreply.github.com>2023-03-12 13:58:25 +0100
committerRincewindsHat <12514511+RincewindsHat@users.noreply.github.com>2023-04-18 00:33:33 +0200
commitf6f2ba34c713b5bc65936af836be24ebc74faf46 (patch)
tree76e30fa6b381d06b8db61a3d47d31ceebbec359e /lib/utils_base.c
parent7c98e2b345b91d8ef3fb1f7a1bcf74194d54c966 (diff)
downloadmonitoring-plugins-f6f2ba3.tar.gz
Fix hash creation
Diffstat (limited to 'lib/utils_base.c')
-rw-r--r--lib/utils_base.c18
1 files 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) {
404char *_np_state_generate_key() { 404char *_np_state_generate_key() {
405 int i; 405 int i;
406 char **argv = this_monitoring_plugin->argv; 406 char **argv = this_monitoring_plugin->argv;
407 unsigned char result[20];
408 char keyname[41]; 407 char keyname[41];
409 char *p=NULL; 408 char *p=NULL;
409
410 unsigned char *result = malloc(256 * sizeof(unsigned char));
411
412 if (result == NULL) {
413 die(STATE_UNKNOWN, _("Failed to allocate memory for hashes: %s"), strerror(errno));
414 }
415
410#ifdef USE_OPENSSL 416#ifdef USE_OPENSSL
411 /* 417 /*
412 * This code path is chosen if openssl is available (which should be the most common 418 * This code path is chosen if openssl is available (which should be the most common
@@ -421,16 +427,22 @@ char *_np_state_generate_key() {
421 EVP_DigestUpdate(ctx, argv[i], strlen(argv[i])); 427 EVP_DigestUpdate(ctx, argv[i], strlen(argv[i]));
422 } 428 }
423 429
424 EVP_DigestFinalXOF(ctx, &result, 20); 430 EVP_DigestFinal(ctx, result, NULL);
425#else 431#else
432
426 struct sha256_ctx ctx; 433 struct sha256_ctx ctx;
427 434
428 for(i=0; i<this_monitoring_plugin->argc; i++) { 435 for(i=0; i<this_monitoring_plugin->argc; i++) {
429 sha256_process_bytes(argv[i], strlen(argv[i]), &ctx); 436 sha256_process_bytes(argv[i], strlen(argv[i]), &ctx);
430 } 437 }
431 438
432 sha256_finish_ctx(&ctx, &result); 439 sha256_finish_ctx(&ctx, result);
433#endif // FOUNDOPENSSL 440#endif // FOUNDOPENSSL
441
442 for (i=0; i<20; ++i) {
443 sprintf(&keyname[2*i], "%02x", result[i]);
444 }
445
434 keyname[40]='\0'; 446 keyname[40]='\0';
435 447
436 p = strdup(keyname); 448 p = strdup(keyname);