From 336b9c38c8c66e260b1ba206b6de9af957011596 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Konrad=20Go=C5=82awski?= Date: Mon, 25 Jul 2022 22:29:49 +0200 Subject: [PATCH] Set up maximum length of example hash Fixes GH-3382 --- src/terminal.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/terminal.c b/src/terminal.c index bb266a1c7..d011ad573 100644 --- a/src/terminal.c +++ b/src/terminal.c @@ -17,6 +17,8 @@ #include "timer.h" #include "terminal.h" +#define MAXIMUM_EXAMPLE_HASH_LENGTH (128) + static const size_t TERMINAL_LINE_LENGTH = 79; static const char *const PROMPT_ACTIVE = "[s]tatus [p]ause [b]ypass [c]heckpoint [f]inish [q]uit => "; @@ -835,11 +837,21 @@ void hash_info_single (hashcat_ctx_t *hashcat_ctx, user_options_extra_t *user_op { event_log_info (hashcat_ctx, " Example.Hash.Format.: hex-encoded (binary file only)"); } - event_log_info (hashcat_ctx, " Example.Hash........: %s", hashconfig->st_hash); } else { event_log_info (hashcat_ctx, " Example.Hash.Format.: plain"); + } + + if (strlen (hashconfig->st_hash) > MAXIMUM_EXAMPLE_HASH_LENGTH) { + char st_hash[MAXIMUM_EXAMPLE_HASH_LENGTH + 1] = { '\0' }; + + strncpy (st_hash, hashconfig->st_hash, MAXIMUM_EXAMPLE_HASH_LENGTH - 3); + strcpy (st_hash + MAXIMUM_EXAMPLE_HASH_LENGTH - 3, "..."); + + event_log_info (hashcat_ctx, " Example.Hash........: [too long example hash for your terminal, use --machine-readable]"); + event_log_info (hashcat_ctx, " %s", st_hash); + } else { event_log_info (hashcat_ctx, " Example.Hash........: %s", hashconfig->st_hash); }