diff --git a/docs/changes.txt b/docs/changes.txt index 1b72b39e4..6116ea751 100644 --- a/docs/changes.txt +++ b/docs/changes.txt @@ -74,6 +74,7 @@ - OpenCL Kernel: Renumbered hash-mode 7600 to 4521 - OpenCL Device: Do a check on available constant memory size and abort if it's less than 64kB - File Reads: Improved error detection on file reads, especially when getting the file stats +- File Locking: Improved error detection on file locks - Sessions: Move out handling of multiple instance from restore file into separate pidfile - Threads: Restored strerror as %m is unsupported by the BSDs - Wordlists: Disable dictstat handling for hash-mode 3000 as it virtually creates words in the wordlist which is not the case for other modes diff --git a/include/locking.h b/include/locking.h index 5e6a30ff7..d35ea1706 100644 --- a/include/locking.h +++ b/include/locking.h @@ -13,7 +13,7 @@ #include #include -int lock_file (FILE *fp); -void unlock_file (FILE *fp); +int lock_file (FILE *fp); +int unlock_file (FILE *fp); #endif // _LOCKING_H diff --git a/src/locking.c b/src/locking.c index 2c8464d46..4b7bd4a26 100644 --- a/src/locking.c +++ b/src/locking.c @@ -27,7 +27,7 @@ int lock_file (FILE *fp) return 0; } -void unlock_file (FILE *fp) +int unlock_file (FILE *fp) { struct flock lock; @@ -35,7 +35,12 @@ void unlock_file (FILE *fp) lock.l_type = F_UNLCK; - fcntl (fileno (fp), F_SETLK, &lock); + if (fcntl (fileno (fp), F_SETLK, &lock)) + { + return -1; + } + + return 0; } #else @@ -47,7 +52,7 @@ int lock_file (MAYBE_UNUSED FILE *fp) return 0; } -void unlock_file (MAYBE_UNUSED FILE *fp) +int unlock_file (MAYBE_UNUSED FILE *fp) { // we should put windows specific code here } diff --git a/src/loopback.c b/src/loopback.c index 2e7197b42..f0c2f2be2 100644 --- a/src/loopback.c +++ b/src/loopback.c @@ -163,7 +163,10 @@ void loopback_write_append (hashcat_ctx_t *hashcat_ctx, const u8 *plain_ptr, con fflush (fp); - unlock_file (fp); + if (unlock_file (fp)) + { + event_log_error (hashcat_ctx, "%s: Failed to unlock file", loopback_ctx->filename); + } loopback_ctx->unused = false; } diff --git a/src/potfile.c b/src/potfile.c index e3461c991..5c92d3e7e 100644 --- a/src/potfile.c +++ b/src/potfile.c @@ -271,7 +271,10 @@ void potfile_write_append (hashcat_ctx_t *hashcat_ctx, const char *out_buf, u8 * fflush (potfile_ctx->fp); - unlock_file (potfile_ctx->fp); + if (unlock_file (potfile_ctx->fp)) + { + event_log_error (hashcat_ctx, "%s: Failed to unlock file", potfile_ctx->filename); + } } void potfile_update_hash (hashcat_ctx_t *hashcat_ctx, hash_t *found, char *line_pw_buf, int line_pw_len)