diff --git a/src/combinator.c b/src/combinator.c index 654ada03f..5ff52d8ac 100644 --- a/src/combinator.c +++ b/src/combinator.c @@ -96,6 +96,16 @@ int combinator_ctx_init (hashcat_ctx_t *hashcat_ctx) return -1; } + if (rc1 == -2) + { + event_log_error (hashcat_ctx, "Error reading wordlist: %s", dictfile1); + + hc_fclose (&fp1); + hc_fclose (&fp2); + + return -1; + } + if (words1_cnt == 0) { event_log_error (hashcat_ctx, "%s: empty file.", dictfile1); @@ -122,6 +132,13 @@ int combinator_ctx_init (hashcat_ctx_t *hashcat_ctx) return -1; } + if (rc2 == -2) + { + event_log_error (hashcat_ctx, "Error reading wordlist: %s", dictfile2); + + return -1; + } + if (words2_cnt == 0) { event_log_error (hashcat_ctx, "%s: empty file.", dictfile2); @@ -199,6 +216,16 @@ int combinator_ctx_init (hashcat_ctx_t *hashcat_ctx) return -1; } + if (rc1 == -2) + { + event_log_error (hashcat_ctx, "Error reading wordlist: %s", dictfile1); + + hc_fclose (&fp1); + hc_fclose (&fp2); + + return -1; + } + if (words1_cnt == 0) { event_log_error (hashcat_ctx, "%s: empty file.", dictfile1); @@ -225,6 +252,13 @@ int combinator_ctx_init (hashcat_ctx_t *hashcat_ctx) return -1; } + if (rc2 == -2) + { + event_log_error (hashcat_ctx, "Error reading wordlist: %s", dictfile2); + + return -1; + } + if (words2_cnt == 0) { event_log_error (hashcat_ctx, "%s: empty file.", dictfile2); @@ -330,6 +364,16 @@ int combinator_ctx_init (hashcat_ctx_t *hashcat_ctx) return -1; } + if (rc1 == -2) + { + event_log_error (hashcat_ctx, "Error reading wordlist: %s", dictfile1); + + hc_fclose (&fp1); + hc_fclose (&fp2); + + return -1; + } + if (words1_cnt == 0) { event_log_error (hashcat_ctx, "%s: empty file.", dictfile1); @@ -356,6 +400,13 @@ int combinator_ctx_init (hashcat_ctx_t *hashcat_ctx) return -1; } + if (rc2 == -2) + { + event_log_error (hashcat_ctx, "Error reading wordlist: %s", dictfile2); + + return -1; + } + if (words2_cnt == 0) { event_log_error (hashcat_ctx, "%s: empty file.", dictfile2); @@ -412,6 +463,13 @@ int combinator_ctx_init (hashcat_ctx_t *hashcat_ctx) return -1; } + if (rc == -2) + { + event_log_error (hashcat_ctx, "Error reading wordlist: %s", dictfile); + + return -1; + } + combinator_ctx->combs_cnt = words_cnt; combinator_ctx->combs_mode = COMBINATOR_MODE_BASE_LEFT; } diff --git a/src/filehandling.c b/src/filehandling.c index 9a2d0ea39..712ccdb66 100644 --- a/src/filehandling.c +++ b/src/filehandling.c @@ -410,6 +410,17 @@ size_t hc_fread (void *ptr, size_t size, size_t nmemb, HCFILE *fp) else if (fp->gfp) { n = gzfread (ptr, size, nmemb, fp->gfp); + + // Double check to make sure that it successfully read 0 bytes instead of erroring + if (n == 0) + { + int errnum; + gzerror (fp->gfp, &errnum); + if (errnum != Z_OK) + { + return (size_t) -1; + } + } } else if (fp->ufp) { diff --git a/src/straight.c b/src/straight.c index 36d3a8eb8..7a75a7d66 100644 --- a/src/straight.c +++ b/src/straight.c @@ -91,6 +91,13 @@ int straight_ctx_update_loop (hashcat_ctx_t *hashcat_ctx) return -1; } + if (rc == -2) + { + event_log_error (hashcat_ctx, "Error reading wordlist: %s", straight_ctx->dict); + + return -1; + } + if (status_ctx->words_cnt == 0) { logfile_sub_msg ("STOP"); @@ -125,6 +132,13 @@ int straight_ctx_update_loop (hashcat_ctx_t *hashcat_ctx) return -1; } + + if (rc == -2) + { + event_log_error (hashcat_ctx, "Error reading wordlist: %s", combinator_ctx->dict1); + + return -1; + } } else if (combinator_ctx->combs_mode == COMBINATOR_MODE_BASE_RIGHT) { @@ -147,6 +161,13 @@ int straight_ctx_update_loop (hashcat_ctx_t *hashcat_ctx) return -1; } + + if (rc == -2) + { + event_log_error (hashcat_ctx, "Error reading wordlist: %s", combinator_ctx->dict2); + + return -1; + } } if (status_ctx->words_cnt == 0) @@ -194,6 +215,13 @@ int straight_ctx_update_loop (hashcat_ctx_t *hashcat_ctx) return -1; } + if (rc == -2) + { + event_log_error (hashcat_ctx, "Error reading wordlist: %s", straight_ctx->dict); + + return -1; + } + if (status_ctx->words_cnt == 0) { logfile_sub_msg ("STOP"); @@ -234,6 +262,13 @@ int straight_ctx_update_loop (hashcat_ctx_t *hashcat_ctx) return -1; } + if (rc == -2) + { + event_log_error (hashcat_ctx, "Error reading wordlist: %s", straight_ctx->dict); + + return -1; + } + if ((status_ctx->words_cnt / straight_ctx->kernel_rules_cnt) != hashes->salts_cnt) { event_log_error (hashcat_ctx, "Number of words in wordlist '%s' is not in sync with number of unique salts", straight_ctx->dict); diff --git a/src/wordlist.c b/src/wordlist.c index 1776b4885..0511381b6 100644 --- a/src/wordlist.c +++ b/src/wordlist.c @@ -60,6 +60,11 @@ int load_segment (hashcat_ctx_t *hashcat_ctx, HCFILE *fp) wl_data->cnt = hc_fread (wl_data->buf, 1, wl_data->incr - 1000, fp); + if (wl_data->cnt == (size_t) -1) + { + return -1; + } + wl_data->buf[wl_data->cnt] = 0; if (wl_data->cnt == 0) return 0; @@ -339,7 +344,12 @@ void get_next_word (hashcat_ctx_t *hashcat_ctx, HCFILE *fp, char **out_buf, u32 return; } - load_segment (hashcat_ctx, fp); + if (load_segment (hashcat_ctx, fp) == -1) + { + event_log_error (hashcat_ctx, "Error reading file!\n"); + + return; + } get_next_word (hashcat_ctx, fp, out_buf, out_len); } @@ -559,9 +569,12 @@ int count_words (hashcat_ctx_t *hashcat_ctx, HCFILE *fp, const char *dictfile, u u64 cnt2 = 0; while (!hc_feof (fp)) - { - load_segment (hashcat_ctx, fp); - + { + if (load_segment (hashcat_ctx, fp) == -1) + { + return -2; + } + comp += wl_data->cnt; u64 i = 0;