From f5f17997b2a6e539fc411c22d68cbae4bda54fa7 Mon Sep 17 00:00:00 2001 From: Rosen Penev Date: Wed, 30 Nov 2016 14:45:21 -0800 Subject: [PATCH 1/2] Fix cppcheck warnings --- src/mpsp.c | 8 ++++++-- src/opencl.c | 11 ++++++++++- src/status.c | 2 +- 3 files changed, 17 insertions(+), 4 deletions(-) diff --git a/src/mpsp.c b/src/mpsp.c index f8650a685..bfdf4a2f2 100644 --- a/src/mpsp.c +++ b/src/mpsp.c @@ -551,10 +551,14 @@ static int mp_setup_usr (hashcat_ctx_t *hashcat_ctx, cs_t *mp_sys, cs_t *mp_usr, { event_log_error (hashcat_ctx, "%s: Custom charset file is too large", buf); + fclose (fp); + return -1; } - - fclose (fp); + else + { + fclose (fp); + } if (nread == 0) { diff --git a/src/opencl.c b/src/opencl.c index 9b4fda09e..56e34f0e8 100644 --- a/src/opencl.c +++ b/src/opencl.c @@ -62,7 +62,16 @@ static int ocl_check_dri (MAYBE_UNUSED hashcat_ctx_t *hashcat_ctx) u32 vendor = 0; - if (fscanf (fd_drm, "0x%x", &vendor) != 1) return 0; + if (fscanf (fd_drm, "0x%x", &vendor) != 1) + { + fclose (fd_drm); + + return 0; + } + else + { + fclose (fd_drm); + } if (vendor != 4098) return 0; diff --git a/src/status.c b/src/status.c index 0874520de..486f6743b 100644 --- a/src/status.c +++ b/src/status.c @@ -1637,7 +1637,7 @@ char *status_get_hwmon_dev (const hashcat_ctx_t *hashcat_ctx, const int device_i } else { - output_len = snprintf (output_buf, HCBUFSIZ_TINY - 1, "N/A"); + snprintf (output_buf, HCBUFSIZ_TINY - 1, "N/A"); } hc_thread_mutex_unlock (status_ctx->mux_hwmon); From 4d09cc10fdd77b34e38dcbd959f780f2c3a71abd Mon Sep 17 00:00:00 2001 From: Rosen Penev Date: Wed, 30 Nov 2016 15:02:26 -0800 Subject: [PATCH 2/2] Fix some formats and conversion errors --- include/common.h | 1 - include/types.h | 2 +- src/affinity.c | 2 +- src/hwmon.c | 14 +++++++------- src/interface.c | 2 +- src/logfile.c | 4 ++-- src/main.c | 8 ++++---- src/opencl.c | 18 +++++++++--------- src/outfile_check.c | 8 ++++---- src/restore.c | 2 +- src/terminal.c | 4 ++-- src/tuningdb.c | 10 +++++----- src/user_options.c | 4 ++-- 13 files changed, 39 insertions(+), 40 deletions(-) diff --git a/include/common.h b/include/common.h index a747acbd2..58312f2cb 100644 --- a/include/common.h +++ b/include/common.h @@ -23,7 +23,6 @@ #define _GNU_SOURCE #define _FILE_OFFSET_BITS 64 -#define _LARGEFILE64_SOURCE #define NOMINMAX 1 diff --git a/include/types.h b/include/types.h index fba9e44bf..bcfd6a9d3 100644 --- a/include/types.h +++ b/include/types.h @@ -673,7 +673,7 @@ typedef struct hash typedef struct outfile_data { char *file_name; - long seek; + off_t seek; time_t ctime; } outfile_data_t; diff --git a/src/affinity.c b/src/affinity.c index c8b82b070..8461ac33c 100644 --- a/src/affinity.c +++ b/src/affinity.c @@ -84,7 +84,7 @@ int set_cpu_affinity (MAYBE_UNUSED hashcat_ctx_t *hashcat_ctx) if (cpu_id > 32) { - event_log_error (hashcat_ctx, "Invalid cpu_id %u specified", cpu_id); + event_log_error (hashcat_ctx, "Invalid cpu_id %d specified", cpu_id); return (-1); } diff --git a/src/hwmon.c b/src/hwmon.c index a4eb9bd31..fb6d9e666 100644 --- a/src/hwmon.c +++ b/src/hwmon.c @@ -1051,13 +1051,13 @@ static int nvapi_init (hashcat_ctx_t *hashcat_ctx) } HC_LOAD_FUNC(nvapi, nvapi_QueryInterface, NVAPI_QUERYINTERFACE, NVAPI, 0) - HC_LOAD_ADDR(nvapi, NvAPI_Initialize, NVAPI_INITIALIZE, nvapi_QueryInterface, 0x0150E828, NVAPI, 0) - HC_LOAD_ADDR(nvapi, NvAPI_Unload, NVAPI_UNLOAD, nvapi_QueryInterface, 0xD22BDD7E, NVAPI, 0) - HC_LOAD_ADDR(nvapi, NvAPI_GetErrorMessage, NVAPI_GETERRORMESSAGE, nvapi_QueryInterface, 0x6C2D048C, NVAPI, 0) - HC_LOAD_ADDR(nvapi, NvAPI_EnumPhysicalGPUs, NVAPI_ENUMPHYSICALGPUS, nvapi_QueryInterface, 0xE5AC921F, NVAPI, 0) - HC_LOAD_ADDR(nvapi, NvAPI_GPU_GetPerfPoliciesInfo, NVAPI_GPU_GETPERFPOLICIESINFO, nvapi_QueryInterface, 0x409D9841, NVAPI, 0) - HC_LOAD_ADDR(nvapi, NvAPI_GPU_GetPerfPoliciesStatus, NVAPI_GPU_GETPERFPOLICIESSTATUS, nvapi_QueryInterface, 0x3D358A0C, NVAPI, 0) - HC_LOAD_ADDR(nvapi, NvAPI_GPU_SetCoolerLevels, NVAPI_GPU_SETCOOLERLEVELS, nvapi_QueryInterface, 0x891FA0AE, NVAPI, 0) + HC_LOAD_ADDR(nvapi, NvAPI_Initialize, NVAPI_INITIALIZE, nvapi_QueryInterface, 0x0150E828u, NVAPI, 0) + HC_LOAD_ADDR(nvapi, NvAPI_Unload, NVAPI_UNLOAD, nvapi_QueryInterface, 0xD22BDD7Eu, NVAPI, 0) + HC_LOAD_ADDR(nvapi, NvAPI_GetErrorMessage, NVAPI_GETERRORMESSAGE, nvapi_QueryInterface, 0x6C2D048Cu, NVAPI, 0) + HC_LOAD_ADDR(nvapi, NvAPI_EnumPhysicalGPUs, NVAPI_ENUMPHYSICALGPUS, nvapi_QueryInterface, 0xE5AC921Fu, NVAPI, 0) + HC_LOAD_ADDR(nvapi, NvAPI_GPU_GetPerfPoliciesInfo, NVAPI_GPU_GETPERFPOLICIESINFO, nvapi_QueryInterface, 0x409D9841u, NVAPI, 0) + HC_LOAD_ADDR(nvapi, NvAPI_GPU_GetPerfPoliciesStatus, NVAPI_GPU_GETPERFPOLICIESSTATUS, nvapi_QueryInterface, 0x3D358A0Cu, NVAPI, 0) + HC_LOAD_ADDR(nvapi, NvAPI_GPU_SetCoolerLevels, NVAPI_GPU_SETCOOLERLEVELS, nvapi_QueryInterface, 0x891FA0AEu, NVAPI, 0) return 0; } diff --git a/src/interface.c b/src/interface.c index 07874f51b..20eb33983 100644 --- a/src/interface.c +++ b/src/interface.c @@ -13311,7 +13311,7 @@ int ascii_digest (hashcat_ctx_t *hashcat_ctx, char *out_buf, const size_t out_le { snprintf (out_buf, out_len - 1, "0x0100%s%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x", (char *) salt.salt_buf, - 0, 0, 0, 0, 0, + 0u, 0u, 0u, 0u, 0u, digest_buf[0], digest_buf[1], digest_buf[2], diff --git a/src/logfile.c b/src/logfile.c index b3fd662b3..7def3c29c 100644 --- a/src/logfile.c +++ b/src/logfile.c @@ -29,7 +29,7 @@ void logfile_generate_topid (hashcat_ctx_t *hashcat_ctx) const int id = logfile_generate_id (); - snprintf (logfile_ctx->topid, 1 + 16, "TOP%08x", id); + snprintf (logfile_ctx->topid, 1 + 16, "TOP%08x", (u32) id); } void logfile_generate_subid (hashcat_ctx_t *hashcat_ctx) @@ -40,7 +40,7 @@ void logfile_generate_subid (hashcat_ctx_t *hashcat_ctx) const int id = logfile_generate_id (); - snprintf (logfile_ctx->subid, 1 + 16, "SUB%08x", id); + snprintf (logfile_ctx->subid, 1 + 16, "SUB%08x", (u32) id); } void logfile_append (hashcat_ctx_t *hashcat_ctx, const char *fmt, ...) diff --git a/src/main.c b/src/main.c index afc2ce5af..c91d9a298 100644 --- a/src/main.c +++ b/src/main.c @@ -543,7 +543,7 @@ static void main_monitor_throttle1 (MAYBE_UNUSED hashcat_ctx_t *hashcat_ctx, MAY u32 *device_id = (u32 *) buf; - event_log_warning (hashcat_ctx, "Drivers temperature threshold hit on GPU #%d, expect performance to drop...", *device_id + 1); + event_log_warning (hashcat_ctx, "Drivers temperature threshold hit on GPU #%u, expect performance to drop...", *device_id + 1); if ((user_options_extra->wordlist_mode == WL_MODE_FILE) || (user_options_extra->wordlist_mode == WL_MODE_MASK)) { @@ -565,7 +565,7 @@ static void main_monitor_throttle2 (MAYBE_UNUSED hashcat_ctx_t *hashcat_ctx, MAY u32 *device_id = (u32 *) buf; - event_log_warning (hashcat_ctx, "Drivers temperature threshold hit on GPU #%d, expect performance to drop...", *device_id + 1); + event_log_warning (hashcat_ctx, "Drivers temperature threshold hit on GPU #%u, expect performance to drop...", *device_id + 1); if ((user_options_extra->wordlist_mode == WL_MODE_FILE) || (user_options_extra->wordlist_mode == WL_MODE_MASK)) { @@ -587,7 +587,7 @@ static void main_monitor_throttle3 (MAYBE_UNUSED hashcat_ctx_t *hashcat_ctx, MAY u32 *device_id = (u32 *) buf; - event_log_warning (hashcat_ctx, "Drivers temperature threshold hit on GPU #%d, expect performance to drop...", *device_id + 1); + event_log_warning (hashcat_ctx, "Drivers temperature threshold hit on GPU #%u, expect performance to drop...", *device_id + 1); event_log_warning (hashcat_ctx, ""); if ((user_options_extra->wordlist_mode == WL_MODE_FILE) || (user_options_extra->wordlist_mode == WL_MODE_MASK)) @@ -700,7 +700,7 @@ static void main_wordlist_cache_hit (MAYBE_UNUSED hashcat_ctx_t *hashcat_ctx, MA cache_hit_t *cache_hit = (cache_hit_t *) buf; - event_log_info (hashcat_ctx, "Cache-hit dictionary stats %s: %" PRIu64 " bytes, %" PRIu64 " words, %" PRIu64 " keyspace", cache_hit->dictfile, cache_hit->stat.st_size, cache_hit->cached_cnt, cache_hit->keyspace); + event_log_info (hashcat_ctx, "Cache-hit dictionary stats %s: %" PRId64 " bytes, %" PRIu64 " words, %" PRIu64 " keyspace", cache_hit->dictfile, cache_hit->stat.st_size, cache_hit->cached_cnt, cache_hit->keyspace); event_log_info (hashcat_ctx, ""); } diff --git a/src/opencl.c b/src/opencl.c index 56e34f0e8..a593c1dd1 100644 --- a/src/opencl.c +++ b/src/opencl.c @@ -190,7 +190,7 @@ static int setup_opencl_platforms_filter (hashcat_ctx_t *hashcat_ctx, const char if (platform < 1 || platform > 32) { - event_log_error (hashcat_ctx, "Invalid OpenCL platform %u specified", platform); + event_log_error (hashcat_ctx, "Invalid OpenCL platform %d specified", platform); return -1; } @@ -229,7 +229,7 @@ static int setup_devices_filter (hashcat_ctx_t *hashcat_ctx, const char *opencl_ if (device_id < 1 || device_id > 32) { - event_log_error (hashcat_ctx, "Invalid device_id %u specified", device_id); + event_log_error (hashcat_ctx, "Invalid device_id %d specified", device_id); return -1; } @@ -268,7 +268,7 @@ static int setup_device_types_filter (hashcat_ctx_t *hashcat_ctx, const char *op if (device_type < 1 || device_type > 3) { - event_log_error (hashcat_ctx, "Invalid device_type %u specified", device_type); + event_log_error (hashcat_ctx, "Invalid device_type %d specified", device_type); return -1; } @@ -2141,7 +2141,7 @@ int opencl_ctx_init (hashcat_ctx_t *hashcat_ctx) if (opencl_platforms_filter > platform_cnt_mask) { - event_log_error (hashcat_ctx, "The platform selected by the --opencl-platforms parameter is larger than the number of available platforms (%d)", platforms_cnt); + event_log_error (hashcat_ctx, "The platform selected by the --opencl-platforms parameter is larger than the number of available platforms (%u)", platforms_cnt); return -1; } @@ -2955,7 +2955,7 @@ int opencl_ctx_devices_init (hashcat_ctx_t *hashcat_ctx, const int comptime) if (opencl_ctx->devices_filter > devices_cnt_mask) { - event_log_error (hashcat_ctx, "The device specified by the --opencl-devices parameter is larger than the number of available devices (%d)", devices_cnt); + event_log_error (hashcat_ctx, "The device specified by the --opencl-devices parameter is larger than the number of available devices (%u)", devices_cnt); return -1; } @@ -3472,14 +3472,14 @@ int opencl_session_begin (hashcat_ctx_t *hashcat_ctx) if ((size_scrypt / 4) > device_param->device_maxmem_alloc) { - if (user_options->quiet == false) event_log_warning (hashcat_ctx, "Not enough single-block device memory allocatable to use --scrypt-tmto %d, increasing...", tmto); + if (user_options->quiet == false) event_log_warning (hashcat_ctx, "Not enough single-block device memory allocatable to use --scrypt-tmto %u, increasing...", tmto); continue; } if (size_scrypt > device_param->device_global_mem) { - if (user_options->quiet == false) event_log_warning (hashcat_ctx, "Not enough total device memory allocatable to use --scrypt-tmto %d, increasing...", tmto); + if (user_options->quiet == false) event_log_warning (hashcat_ctx, "Not enough total device memory allocatable to use --scrypt-tmto %u, increasing...", tmto); continue; } @@ -3697,9 +3697,9 @@ int opencl_session_begin (hashcat_ctx_t *hashcat_ctx) char build_opts_new[1024] = { 0 }; #if defined (DEBUG) - snprintf (build_opts_new, sizeof (build_opts_new) - 1, "%s -D VENDOR_ID=%u -D CUDA_ARCH=%d -D VECT_SIZE=%u -D DEVICE_TYPE=%u -D DGST_R0=%u -D DGST_R1=%u -D DGST_R2=%u -D DGST_R3=%u -D DGST_ELEM=%u -D KERN_TYPE=%u -D _unroll -cl-std=CL1.2", build_opts, device_param->platform_vendor_id, (device_param->sm_major * 100) + device_param->sm_minor, device_param->vector_width, (u32) device_param->device_type, hashconfig->dgst_pos0, hashconfig->dgst_pos1, hashconfig->dgst_pos2, hashconfig->dgst_pos3, hashconfig->dgst_size / 4, hashconfig->kern_type); + snprintf (build_opts_new, sizeof (build_opts_new) - 1, "%s -D VENDOR_ID=%u -D CUDA_ARCH=%u -D VECT_SIZE=%u -D DEVICE_TYPE=%u -D DGST_R0=%u -D DGST_R1=%u -D DGST_R2=%u -D DGST_R3=%u -D DGST_ELEM=%u -D KERN_TYPE=%u -D _unroll -cl-std=CL1.2", build_opts, device_param->platform_vendor_id, (device_param->sm_major * 100) + device_param->sm_minor, device_param->vector_width, (u32) device_param->device_type, hashconfig->dgst_pos0, hashconfig->dgst_pos1, hashconfig->dgst_pos2, hashconfig->dgst_pos3, hashconfig->dgst_size / 4, hashconfig->kern_type); #else - snprintf (build_opts_new, sizeof (build_opts_new) - 1, "%s -D VENDOR_ID=%u -D CUDA_ARCH=%d -D VECT_SIZE=%u -D DEVICE_TYPE=%u -D DGST_R0=%u -D DGST_R1=%u -D DGST_R2=%u -D DGST_R3=%u -D DGST_ELEM=%u -D KERN_TYPE=%u -D _unroll -cl-std=CL1.2 -w", build_opts, device_param->platform_vendor_id, (device_param->sm_major * 100) + device_param->sm_minor, device_param->vector_width, (u32) device_param->device_type, hashconfig->dgst_pos0, hashconfig->dgst_pos1, hashconfig->dgst_pos2, hashconfig->dgst_pos3, hashconfig->dgst_size / 4, hashconfig->kern_type); + snprintf (build_opts_new, sizeof (build_opts_new) - 1, "%s -D VENDOR_ID=%u -D CUDA_ARCH=%u -D VECT_SIZE=%u -D DEVICE_TYPE=%u -D DGST_R0=%u -D DGST_R1=%u -D DGST_R2=%u -D DGST_R3=%u -D DGST_ELEM=%u -D KERN_TYPE=%u -D _unroll -cl-std=CL1.2 -w", build_opts, device_param->platform_vendor_id, (device_param->sm_major * 100) + device_param->sm_minor, device_param->vector_width, (u32) device_param->device_type, hashconfig->dgst_pos0, hashconfig->dgst_pos1, hashconfig->dgst_pos2, hashconfig->dgst_pos3, hashconfig->dgst_size / 4, hashconfig->kern_type); #endif strncpy (build_opts, build_opts_new, sizeof (build_opts) - 1); diff --git a/src/outfile_check.c b/src/outfile_check.c index 76f0ea247..52b7bc280 100644 --- a/src/outfile_check.c +++ b/src/outfile_check.c @@ -148,13 +148,13 @@ static int outfile_remove (hashcat_ctx_t *hashcat_ctx) if (ptr == NULL) break; - int line_len = strlen (line_buf); + size_t line_len = strlen (line_buf); - if (line_len <= 0) continue; + if (line_len == 0) continue; - int iter = MAX_CUT_TRIES; + size_t iter = MAX_CUT_TRIES; - for (u32 i = line_len - 1; i && iter; i--, line_len--) + for (size_t i = line_len - 1; i && iter; i--, line_len--) { if (line_buf[i] != separator) continue; diff --git a/src/restore.c b/src/restore.c index 0c3360af5..8787b5fb4 100644 --- a/src/restore.c +++ b/src/restore.c @@ -71,7 +71,7 @@ static int check_running_process (hashcat_ctx_t *hashcat_ctx) if (strcmp (argv0_r, pidbin_r) == 0) { - event_log_error (hashcat_ctx, "Already an instance %s running on pid %d", pidbin, rd->pid); + event_log_error (hashcat_ctx, "Already an instance %s running on pid %u", pidbin, rd->pid); return -1; } diff --git a/src/terminal.c b/src/terminal.c index 2a954b483..2b161482e 100644 --- a/src/terminal.c +++ b/src/terminal.c @@ -955,7 +955,7 @@ void status_display (hashcat_ctx_t *hashcat_ctx) } event_log_info (hashcat_ctx, - "Recovered........: %u/%u (%.2f%%) Digests, %u/%u (%.2f%%) Salts", + "Recovered........: %d/%d (%.2f%%) Digests, %d/%d (%.2f%%) Salts", hashcat_status->digests_done, hashcat_status->digests_cnt, hashcat_status->digests_percent, @@ -1066,7 +1066,7 @@ void status_benchmark_automate (hashcat_ctx_t *hashcat_ctx) if (device_info->skipped_dev == true) continue; - event_log_info (hashcat_ctx, "%u:%u:%d:%d:%.2f:%" PRIu64, device_id + 1, hash_mode, device_info->corespeed_dev, device_info->memoryspeed_dev, device_info->exec_msec_dev, (u64) (device_info->hashes_msec_dev_benchmark * 1000)); + event_log_info (hashcat_ctx, "%d:%u:%d:%d:%.2f:%" PRIu64, device_id + 1, hash_mode, device_info->corespeed_dev, device_info->memoryspeed_dev, device_info->exec_msec_dev, (u64) (device_info->hashes_msec_dev_benchmark * 1000)); } hcfree (hashcat_status); diff --git a/src/tuningdb.c b/src/tuningdb.c index d8c1db5e6..9726f00b5 100644 --- a/src/tuningdb.c +++ b/src/tuningdb.c @@ -152,7 +152,7 @@ int tuning_db_init (hashcat_ctx_t *hashcat_ctx) (token_ptr[1][0] != '3') && (token_ptr[1][0] != '*')) { - event_log_warning (hashcat_ctx, "Tuning-db: Invalid attack_mode '%c' in Line '%u'", token_ptr[1][0], line_num); + event_log_warning (hashcat_ctx, "Tuning-db: Invalid attack_mode '%c' in Line '%d'", token_ptr[1][0], line_num); continue; } @@ -163,7 +163,7 @@ int tuning_db_init (hashcat_ctx_t *hashcat_ctx) (token_ptr[3][0] != '8') && (token_ptr[3][0] != 'N')) { - event_log_warning (hashcat_ctx, "Tuning-db: Invalid vector_width '%c' in Line '%u'", token_ptr[3][0], line_num); + event_log_warning (hashcat_ctx, "Tuning-db: Invalid vector_width '%c' in Line '%d'", token_ptr[3][0], line_num); continue; } @@ -186,7 +186,7 @@ int tuning_db_init (hashcat_ctx_t *hashcat_ctx) if ((kernel_accel < 1) || (kernel_accel > 1024)) { - event_log_warning (hashcat_ctx, "Tuning-db: Invalid kernel_accel '%d' in Line '%u'", kernel_accel, line_num); + event_log_warning (hashcat_ctx, "Tuning-db: Invalid kernel_accel '%d' in Line '%d'", kernel_accel, line_num); continue; } @@ -202,7 +202,7 @@ int tuning_db_init (hashcat_ctx_t *hashcat_ctx) if ((kernel_loops < 1) || (kernel_loops > 1024)) { - event_log_warning (hashcat_ctx, "Tuning-db: Invalid kernel_loops '%d' in Line '%u'", kernel_loops, line_num); + event_log_warning (hashcat_ctx, "Tuning-db: Invalid kernel_loops '%d' in Line '%d'", kernel_loops, line_num); continue; } @@ -225,7 +225,7 @@ int tuning_db_init (hashcat_ctx_t *hashcat_ctx) } else { - event_log_warning (hashcat_ctx, "Tuning-db: Invalid number of token in Line '%u'", line_num); + event_log_warning (hashcat_ctx, "Tuning-db: Invalid number of token in Line '%d'", line_num); continue; } diff --git a/src/user_options.c b/src/user_options.c index fb288662e..7a6024e32 100644 --- a/src/user_options.c +++ b/src/user_options.c @@ -571,7 +571,7 @@ int user_options_sanity (hashcat_ctx_t *hashcat_ctx) if ((user_options->workload_profile < 1) || (user_options->workload_profile > 4)) { - event_log_error (hashcat_ctx, "workload-profile %i not available", user_options->workload_profile); + event_log_error (hashcat_ctx, "workload-profile %u not available", user_options->workload_profile); return -1; } @@ -580,7 +580,7 @@ int user_options_sanity (hashcat_ctx_t *hashcat_ctx) { if (is_power_of_2 (user_options->opencl_vector_width) == false || user_options->opencl_vector_width > 16) { - event_log_error (hashcat_ctx, "opencl-vector-width %i not allowed", user_options->opencl_vector_width); + event_log_error (hashcat_ctx, "opencl-vector-width %u not allowed", user_options->opencl_vector_width); return -1; }