From 907fb52c7b1db80389a2cdd500c4c4e823118efe Mon Sep 17 00:00:00 2001 From: jsteube Date: Wed, 16 Nov 2016 17:06:39 +0100 Subject: [PATCH] Replaced all calls to gmtime() with gmtime_r() to ensure thread safety with exception to windows, because there's no _gmtime64_r() for windows --- src/status.c | 24 +++++++++++------------- 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/src/status.c b/src/status.c index a314f4f26..960b22c4f 100644 --- a/src/status.c +++ b/src/status.c @@ -29,6 +29,8 @@ static const char ST_0007[] = "Quit"; static const char ST_0008[] = "Bypass"; static const char ST_9999[] = "Unknown! Bug!"; +static const char UNITS[7] = { ' ', 'k', 'M', 'G', 'T', 'P', 'E' }; + static char *status_get_rules_file (const hashcat_ctx_t *hashcat_ctx) { const user_options_t *user_options = hashcat_ctx->user_options; @@ -108,8 +110,6 @@ void format_speed_display (double val, char *buf, size_t len) return; } - char units[7] = { ' ', 'k', 'M', 'G', 'T', 'P', 'E' }; - u32 level = 0; while (val > 99999) @@ -127,7 +127,7 @@ void format_speed_display (double val, char *buf, size_t len) } else { - snprintf (buf, len - 1, "%.1f %c", val, units[level]); + snprintf (buf, len - 1, "%.1f %c", val, UNITS[level]); } } @@ -867,25 +867,19 @@ char *status_get_time_started_relative (const hashcat_ctx_t *hashcat_ctx) const time_t time_start = status_ctx->runtime_start; #if defined (_WIN) - __time64_t sec_run = time_now - time_start; - #else - time_t sec_run = time_now - time_start; - #endif struct tm *tmp; #if defined (_WIN) - tmp = _gmtime64 (&sec_run); - #else + struct tm tm; - tmp = gmtime (&sec_run); - + tmp = gmtime_r (&sec_run, &tm); #endif char *display_run = (char *) malloc (HCBUFSIZ_TINY); @@ -999,7 +993,9 @@ char *status_get_time_estimated_relative (const hashcat_ctx_t *hashcat_ctx) #if defined (_WIN) tmp = _gmtime64 (&sec_etc); #else - tmp = gmtime (&sec_etc); + struct tm tm; + + tmp = gmtime_r (&sec_etc, &tm); #endif char *display = (char *) malloc (HCBUFSIZ_TINY); @@ -1025,7 +1021,9 @@ char *status_get_time_estimated_relative (const hashcat_ctx_t *hashcat_ctx) #if defined (_WIN) tmp_left = _gmtime64 (&sec_left); #else - tmp_left = gmtime (&sec_left); + struct tm tm_left; + + tmp_left = gmtime_r (&sec_left, &tm_left); #endif char *display_left = (char *) malloc (HCBUFSIZ_TINY);