diff --git a/docs/changes.txt b/docs/changes.txt index 283e3c0d4..a4a17bfd8 100644 --- a/docs/changes.txt +++ b/docs/changes.txt @@ -82,6 +82,7 @@ - Fixed bug in grep out-of-memory workaround on Unit Test - Fixed bug in input_tokenizer when TOKEN_ATTR_FIXED_LENGTH is used and refactor modules - Fixed bug in --stdout that caused certain rules to malfunction +- Fixed bug in --stdout when multiple computing devices are active - Fixed build failed for 10700 optimized with Apple Metal - Fixed build failed for 13772 and 13773 with Apple Metal - Fixed build failed for 18400 with Apple Metal diff --git a/include/types.h b/include/types.h index e6ea946f9..6b508d7f0 100644 --- a/include/types.h +++ b/include/types.h @@ -2122,6 +2122,8 @@ typedef struct outfile_ctx char *filename; + hc_thread_mutex_t mux_outfile; + } outfile_ctx_t; typedef struct pot diff --git a/src/outfile.c b/src/outfile.c index b14b56a7a..43ddb8611 100644 --- a/src/outfile.c +++ b/src/outfile.c @@ -15,6 +15,7 @@ #include "backend.h" #include "shared.h" #include "locking.h" +#include "thread.h" #include "outfile.h" u32 outfile_format_parse (const char *format_string) @@ -506,6 +507,8 @@ int outfile_init (hashcat_ctx_t *hashcat_ctx) outfile_ctx->outfile_json = user_options->outfile_json; outfile_ctx->is_fifo = hc_path_is_fifo (outfile_ctx->filename); + hc_thread_mutex_init (outfile_ctx->mux_outfile); + return 0; } @@ -513,6 +516,8 @@ void outfile_destroy (hashcat_ctx_t *hashcat_ctx) { outfile_ctx_t *outfile_ctx = hashcat_ctx->outfile_ctx; + hc_thread_mutex_delete (outfile_ctx->mux_outfile); + if (outfile_ctx->is_fifo == true && outfile_ctx->fp.pfp != NULL) { hc_unlockfile (&outfile_ctx->fp); diff --git a/src/stdout.c b/src/stdout.c index 429836793..127232d0e 100644 --- a/src/stdout.c +++ b/src/stdout.c @@ -12,6 +12,7 @@ #include "mpsp.h" #include "backend.h" #include "shared.h" +#include "thread.h" #include "stdout.h" static void out_flush (out_t *out) @@ -59,6 +60,10 @@ int process_stdout (hashcat_ctx_t *hashcat_ctx, hc_device_param_t *device_param, straight_ctx_t *straight_ctx = hashcat_ctx->straight_ctx; user_options_t *user_options = hashcat_ctx->user_options; + // prevent wrong candidates in output when backend_ctx->backend_devices_active > 1 + + hc_thread_mutex_lock (outfile_ctx->mux_outfile); + char *filename = outfile_ctx->filename; out_t out; @@ -69,6 +74,8 @@ int process_stdout (hashcat_ctx_t *hashcat_ctx, hc_device_param_t *device_param, { event_log_error (hashcat_ctx, "%s: %s", filename, strerror (errno)); + hc_thread_mutex_unlock (outfile_ctx->mux_outfile); + return -1; } @@ -78,6 +85,8 @@ int process_stdout (hashcat_ctx_t *hashcat_ctx, hc_device_param_t *device_param, event_log_error (hashcat_ctx, "%s: %s", filename, strerror (errno)); + hc_thread_mutex_unlock (outfile_ctx->mux_outfile); + return -1; } } @@ -341,5 +350,7 @@ int process_stdout (hashcat_ctx_t *hashcat_ctx, hc_device_param_t *device_param, hc_fclose (&out.fp); } + hc_thread_mutex_unlock (outfile_ctx->mux_outfile); + return rc; }