Fix race condition in thread_keypress
[hashcat.git] / src / hashcat.c
index 36a6e84..e57f4ba 100644 (file)
@@ -4780,7 +4780,7 @@ static uint get_work (hc_device_param_t *device_param, const u64 max)
   hc_thread_mutex_lock (mux_dispatcher);
 
   const u64 words_cur  = data.words_cur;
-  const u64 words_base = (data.limit == 0) ? data.words_base : data.limit;
+  const u64 words_base = (data.limit == 0) ? data.words_base : MIN (data.limit, data.words_base);
 
   device_param->words_off = words_cur;
 
@@ -17561,7 +17561,10 @@ int main (int argc, char **argv)
 
         logfile_sub_msg ("START");
 
-        data.devices_status = STATUS_INIT;
+        if ((data.devices_status != STATUS_CRACKED) && (data.devices_status != STATUS_ABORTED) && (data.devices_status != STATUS_QUIT))
+        {
+          data.devices_status = STATUS_INIT;
+        }
 
         memset (data.words_progress_done,     0, data.salts_cnt * sizeof (u64));
         memset (data.words_progress_rejected, 0, data.salts_cnt * sizeof (u64));
@@ -18089,7 +18092,10 @@ int main (int argc, char **argv)
 
         hc_thread_t *c_threads = (hc_thread_t *) mycalloc (data.devices_cnt, sizeof (hc_thread_t));
 
-        data.devices_status = STATUS_AUTOTUNE;
+        if ((data.devices_status != STATUS_CRACKED) && (data.devices_status != STATUS_ABORTED) && (data.devices_status != STATUS_QUIT))
+        {
+          data.devices_status = STATUS_AUTOTUNE;
+        }
 
         for (uint device_id = 0; device_id < data.devices_cnt; device_id++)
         {
@@ -18143,7 +18149,10 @@ int main (int argc, char **argv)
          * create cracker threads
          */
 
-        data.devices_status = STATUS_RUNNING;
+        if ((data.devices_status != STATUS_CRACKED) && (data.devices_status != STATUS_ABORTED) && (data.devices_status != STATUS_QUIT))
+        {
+          data.devices_status = STATUS_RUNNING;
+        }
 
         if (initial_restore_done == 0)
         {
@@ -18192,11 +18201,6 @@ int main (int argc, char **argv)
 
         local_free (c_threads);
 
-        if ((data.devices_status != STATUS_CRACKED) && (data.devices_status != STATUS_ABORTED) && (data.devices_status != STATUS_QUIT) && (data.devices_status != STATUS_BYPASS))
-        {
-          data.devices_status = STATUS_EXHAUSTED;
-        }
-
         logfile_sub_var_uint ("status-after-work", data.devices_status);
 
         data.restore = 0;
@@ -18256,11 +18260,11 @@ int main (int argc, char **argv)
 
         global_free (subid);
 
-        // from this point we handle bypass as exhausted
+        // from this point we handle bypass as running
 
         if (data.devices_status == STATUS_BYPASS)
         {
-          data.devices_status = STATUS_EXHAUSTED;
+          data.devices_status = STATUS_RUNNING;
         }
 
         // finalize task
@@ -18328,6 +18332,11 @@ int main (int argc, char **argv)
 
     // wait for non-interactive threads
 
+    if ((data.devices_status != STATUS_CRACKED) && (data.devices_status != STATUS_ABORTED) && (data.devices_status != STATUS_QUIT))
+    {
+      data.devices_status = STATUS_EXHAUSTED;
+    }
+
     for (uint thread_idx = 0; thread_idx < ni_threads_cnt; thread_idx++)
     {
       hc_thread_wait (1, &ni_threads[thread_idx]);