From f1d426098332bdc34baa7f8a55d9712efa3ced09 Mon Sep 17 00:00:00 2001 From: Jens Steube Date: Sat, 29 Feb 2020 10:40:47 +0100 Subject: [PATCH] Fix missing hc_unlockfile() --- src/debugfile.c | 2 ++ src/dictstat.c | 9 +++++++++ src/hashes.c | 12 ++++++++++++ src/logfile.c | 2 ++ src/loopback.c | 5 +---- src/outfile.c | 2 ++ src/stdout.c | 7 ++++++- 7 files changed, 34 insertions(+), 5 deletions(-) diff --git a/src/debugfile.c b/src/debugfile.c index 839dcba35..a6ffd3826 100644 --- a/src/debugfile.c +++ b/src/debugfile.c @@ -141,6 +141,8 @@ void debugfile_destroy (hashcat_ctx_t *hashcat_ctx) if (debugfile_ctx->filename) { + hc_unlockfile (&debugfile_ctx->fp); + hc_fclose (&debugfile_ctx->fp); } diff --git a/src/dictstat.c b/src/dictstat.c index caab3deea..15830c68b 100644 --- a/src/dictstat.c +++ b/src/dictstat.c @@ -217,6 +217,15 @@ int dictstat_write (hashcat_ctx_t *hashcat_ctx) hc_fwrite (dictstat_ctx->base, sizeof (dictstat_t), dictstat_ctx->cnt, &fp); + if (hc_unlockfile (&fp) == -1) + { + hc_fclose (&fp); + + event_log_error (hashcat_ctx, "%s: %s", dictstat_ctx->filename, strerror (errno)); + + return -1; + } + hc_fclose (&fp); return 0; diff --git a/src/hashes.c b/src/hashes.c index 73ea47c3b..c5d1df4f3 100644 --- a/src/hashes.c +++ b/src/hashes.c @@ -258,6 +258,18 @@ int save_hash (hashcat_ctx_t *hashcat_ctx) hc_fflush (&fp); + if (hc_unlockfile (&fp) == -1) + { + hc_fclose (&fp); + + event_log_error (hashcat_ctx, "%s: %s", new_hashfile, strerror (errno)); + + free (new_hashfile); + free (old_hashfile); + + return -1; + } + hc_fclose (&fp); unlink (old_hashfile); diff --git a/src/logfile.c b/src/logfile.c index 29f342a4b..d69e15d75 100644 --- a/src/logfile.c +++ b/src/logfile.c @@ -66,6 +66,8 @@ void logfile_append (hashcat_ctx_t *hashcat_ctx, const char *fmt, ...) hc_fflush (&fp); + hc_unlockfile (&fp); + hc_fclose (&fp); } diff --git a/src/loopback.c b/src/loopback.c index d289a70c1..2568971d7 100644 --- a/src/loopback.c +++ b/src/loopback.c @@ -158,10 +158,7 @@ void loopback_write_append (hashcat_ctx_t *hashcat_ctx, const u8 *plain_ptr, con hc_fflush (&loopback_ctx->fp); - if (hc_unlockfile (&loopback_ctx->fp)) - { - event_log_error (hashcat_ctx, "%s: Failed to unlock file", loopback_ctx->filename); - } + hc_unlockfile (&loopback_ctx->fp); loopback_ctx->unused = false; } diff --git a/src/outfile.c b/src/outfile.c index 2e49a4597..a0498b902 100644 --- a/src/outfile.c +++ b/src/outfile.c @@ -533,6 +533,8 @@ void outfile_write_close (hashcat_ctx_t *hashcat_ctx) if (outfile_ctx->fp.pfp == NULL) return; + hc_unlockfile (&outfile_ctx->fp); + hc_fclose (&outfile_ctx->fp); } diff --git a/src/stdout.c b/src/stdout.c index f7a4585f1..102b22d79 100644 --- a/src/stdout.c +++ b/src/stdout.c @@ -291,7 +291,12 @@ int process_stdout (hashcat_ctx_t *hashcat_ctx, hc_device_param_t *device_param, out_flush (&out); - if (filename) hc_fclose (&out.fp); + if (filename) + { + hc_unlockfile (&out.fp); + + hc_fclose (&out.fp); + } return 0; }