From d0f7fee029ade54860fd36025797243b7cf1dd2f Mon Sep 17 00:00:00 2001 From: jsteube Date: Sat, 12 Nov 2016 12:16:41 +0100 Subject: [PATCH] Fixed a bug when loading custom charset from file --- docs/changes.txt | 1 + src/mpsp.c | 37 +++++++++++++++++++++---------------- 2 files changed, 22 insertions(+), 16 deletions(-) diff --git a/docs/changes.txt b/docs/changes.txt index 920828c09..133f44089 100644 --- a/docs/changes.txt +++ b/docs/changes.txt @@ -19,6 +19,7 @@ ## - Fixed a bug when cracking a large salted hashlist status view showed 0H/s but progress counter increased +- Fixed a bug when loading custom charset from file ## ## Algorithms diff --git a/src/mpsp.c b/src/mpsp.c index 50f98db92..a384b41c4 100644 --- a/src/mpsp.c +++ b/src/mpsp.c @@ -539,28 +539,35 @@ static int mp_setup_usr (hashcat_ctx_t *hashcat_ctx, cs_t *mp_sys, cs_t *mp_usr, { FILE *fp = fopen (buf, "rb"); - if (fp == NULL || feof (fp)) // feof() in case if file is empty + if (fp == NULL) // feof() in case if file is empty { const int rc = mp_expand (hashcat_ctx, buf, strlen (buf), mp_sys, mp_usr, index, 1); - if (rc == -1) - { - if (fp) fclose (fp); - - return -1; - } + if (rc == -1) return -1; } else { char mp_file[1024] = { 0 }; - int len = (int) fread (mp_file, 1, sizeof (mp_file) - 1, fp); + const size_t nread = fread (mp_file, 1, sizeof (mp_file) - 1, fp); + + if (!feof (fp)) + { + event_log_error (hashcat_ctx, "%s: File is too large", buf); + + return -1; + } fclose (fp); - fp = NULL; + if (nread == 0) + { + event_log_error (hashcat_ctx, "%s: File is empty", buf); - len = in_superchop (mp_file); + return -1; + } + + const int len = in_superchop (mp_file); if (len == 0) { @@ -578,8 +585,6 @@ static int mp_setup_usr (hashcat_ctx_t *hashcat_ctx, cs_t *mp_sys, cs_t *mp_usr, } } - if (fp) fclose (fp); - return 0; } @@ -1180,10 +1185,10 @@ int mask_ctx_init (hashcat_ctx_t *hashcat_ctx) mp_setup_sys (mask_ctx->mp_sys); - if (user_options->custom_charset_1) mp_setup_usr (hashcat_ctx, mask_ctx->mp_sys, mask_ctx->mp_usr, user_options->custom_charset_1, 0); - if (user_options->custom_charset_2) mp_setup_usr (hashcat_ctx, mask_ctx->mp_sys, mask_ctx->mp_usr, user_options->custom_charset_2, 1); - if (user_options->custom_charset_3) mp_setup_usr (hashcat_ctx, mask_ctx->mp_sys, mask_ctx->mp_usr, user_options->custom_charset_3, 2); - if (user_options->custom_charset_4) mp_setup_usr (hashcat_ctx, mask_ctx->mp_sys, mask_ctx->mp_usr, user_options->custom_charset_4, 3); + if (user_options->custom_charset_1) { const int rc = mp_setup_usr (hashcat_ctx, mask_ctx->mp_sys, mask_ctx->mp_usr, user_options->custom_charset_1, 0); if (rc == -1) return -1; } + if (user_options->custom_charset_2) { const int rc = mp_setup_usr (hashcat_ctx, mask_ctx->mp_sys, mask_ctx->mp_usr, user_options->custom_charset_2, 1); if (rc == -1) return -1; } + if (user_options->custom_charset_3) { const int rc = mp_setup_usr (hashcat_ctx, mask_ctx->mp_sys, mask_ctx->mp_usr, user_options->custom_charset_3, 2); if (rc == -1) return -1; } + if (user_options->custom_charset_4) { const int rc = mp_setup_usr (hashcat_ctx, mask_ctx->mp_sys, mask_ctx->mp_usr, user_options->custom_charset_4, 3); if (rc == -1) return -1; } if (user_options->attack_mode == ATTACK_MODE_BF) {