replace more snprintf calls with hc_asprintf.

pull/1382/head
Rosen Penev 7 years ago
parent 2670791916
commit 4ba19fa7c1

@ -120,11 +120,11 @@ int save_hash (hashcat_ctx_t *hashcat_ctx)
const char *hashfile = hashes->hashfile;
char new_hashfile[256] = { 0 };
char old_hashfile[256] = { 0 };
char *new_hashfile;
char *old_hashfile;
snprintf (new_hashfile, 255, "%s.new", hashfile);
snprintf (old_hashfile, 255, "%s.old", hashfile);
hc_asprintf (&new_hashfile, "%s.new", hashfile);
hc_asprintf (&old_hashfile, "%s.old", hashfile);
unlink (new_hashfile);
@ -1582,9 +1582,9 @@ int hashes_init_selftest (hashcat_ctx_t *hashcat_ctx)
}
else if (hashconfig->opts_type & OPTS_TYPE_BINARY_HASHFILE)
{
char *tmpfile_bin = (char *) hcmalloc (HCBUFSIZ_TINY);
char *tmpfile_bin;
snprintf (tmpfile_bin, HCBUFSIZ_TINY - 1, "%s/selftest.hash", folder_config->session_dir);
hc_asprintf (&tmpfile_bin, "%s/selftest.hash", folder_config->session_dir);
FILE *fp = fopen (tmpfile_bin, "wb");

@ -22,9 +22,9 @@ static bool sysfs_init (hashcat_ctx_t *hashcat_ctx)
memset (sysfs, 0, sizeof (SYSFS_PTR));
char *path = hcmalloc (HCBUFSIZ_TINY);
char *path;
snprintf (path, HCBUFSIZ_TINY - 1, "%s", SYS_BUS_PCI_DEVICES);
hc_asprintf (&path, "%s", SYS_BUS_PCI_DEVICES);
const bool r = hc_path_read (path);
@ -104,11 +104,11 @@ static int hm_SYSFS_get_fan_speed_current (hashcat_ctx_t *hashcat_ctx, const int
if (syspath == NULL) return -1;
char *path_cur = hcmalloc (HCBUFSIZ_TINY);
char *path_max = hcmalloc (HCBUFSIZ_TINY);
char *path_cur;
char *path_max;
snprintf (path_cur, HCBUFSIZ_TINY - 1, "%s/pwm1", syspath);
snprintf (path_max, HCBUFSIZ_TINY - 1, "%s/pwm1_max", syspath);
hc_asprintf (&path_cur, "%s/pwm1", syspath);
hc_asprintf (&path_max, "%s/pwm1_max", syspath);
hcfree (syspath);
@ -196,9 +196,9 @@ static int hm_SYSFS_set_fan_control (hashcat_ctx_t *hashcat_ctx, const int devic
if (syspath == NULL) return -1;
char *path = hcmalloc (HCBUFSIZ_TINY);
char *path;
snprintf (path, HCBUFSIZ_TINY - 1, "%s/pwm1_enable", syspath);
hc_asprintf (&path, "%s/pwm1_enable", syspath);
hcfree (syspath);
@ -228,11 +228,11 @@ static int hm_SYSFS_set_fan_speed_target (hashcat_ctx_t *hashcat_ctx, const int
if (syspath == NULL) return -1;
char *path = hcmalloc (HCBUFSIZ_TINY);
char *path_max = hcmalloc (HCBUFSIZ_TINY);
char *path;
char *path_max;
snprintf (path, HCBUFSIZ_TINY - 1, "%s/pwm1", syspath);
snprintf (path_max, HCBUFSIZ_TINY - 1, "%s/pwm1_max", syspath);
hc_asprintf (&path, "%s/pwm1", syspath);
hc_asprintf (&path_max, "%s/pwm1_max", syspath);
hcfree (syspath);
@ -304,9 +304,9 @@ static int hm_SYSFS_get_temperature_current (hashcat_ctx_t *hashcat_ctx, const i
if (syspath == NULL) return -1;
char *path = hcmalloc (HCBUFSIZ_TINY);
char *path;
snprintf (path, HCBUFSIZ_TINY - 1, "%s/temp1_input", syspath);
hc_asprintf (&path, "%s/temp1_input", syspath);
hcfree (syspath);
@ -349,9 +349,9 @@ static int hm_SYSFS_get_pp_dpm_sclk (hashcat_ctx_t *hashcat_ctx, const int devic
if (syspath == NULL) return -1;
char *path = hcmalloc (HCBUFSIZ_TINY);
char *path;
snprintf (path, HCBUFSIZ_TINY - 1, "%s/pp_dpm_sclk", syspath);
hc_asprintf (&path, "%s/pp_dpm_sclk", syspath);
hcfree (syspath);
@ -404,9 +404,9 @@ static int hm_SYSFS_get_pp_dpm_mclk (hashcat_ctx_t *hashcat_ctx, const int devic
if (syspath == NULL) return -1;
char *path = hcmalloc (HCBUFSIZ_TINY);
char *path;
snprintf (path, HCBUFSIZ_TINY - 1, "%s/pp_dpm_mclk", syspath);
hc_asprintf (&path, "%s/pp_dpm_mclk", syspath);
hcfree (syspath);
@ -459,9 +459,9 @@ static int hm_SYSFS_get_pp_dpm_pcie (hashcat_ctx_t *hashcat_ctx, const int devic
if (syspath == NULL) return -1;
char *path = hcmalloc (HCBUFSIZ_TINY);
char *path;
snprintf (path, HCBUFSIZ_TINY - 1, "%s/pp_dpm_pcie", syspath);
hc_asprintf (&path, "%s/pp_dpm_pcie", syspath);
hcfree (syspath);
@ -515,9 +515,9 @@ static int hm_SYSFS_set_power_dpm_force_performance_level (hashcat_ctx_t *hashca
if (syspath == NULL) return -1;
char *path = hcmalloc (HCBUFSIZ_TINY);
char *path;
snprintf (path, HCBUFSIZ_TINY - 1, "%s/power_dpm_force_performance_level", syspath);
hc_asprintf (&path, "%s/power_dpm_force_performance_level", syspath);
hcfree (syspath);

@ -4441,19 +4441,19 @@ int opencl_session_begin (hashcat_ctx_t *hashcat_ctx)
if (CL_rc == -1) return -1;
char build_opts_update[1024] = { 0 };
char *build_opts_update;
if (opencl_ctx->force_jit_compilation == 1500)
{
snprintf (build_opts_update, sizeof (build_opts_update) - 1, "%s -DDESCRYPT_SALT=%u", build_opts, hashes->salts_buf[0].salt_buf[0]);
hc_asprintf (&build_opts_update, "%s -DDESCRYPT_SALT=%u", build_opts, hashes->salts_buf[0].salt_buf[0]);
}
else if ((opencl_ctx->force_jit_compilation == 8900) || (opencl_ctx->force_jit_compilation == 15700))
{
snprintf (build_opts_update, sizeof (build_opts_update) - 1, "%s -DSCRYPT_N=%u -DSCRYPT_R=%u -DSCRYPT_P=%u -DSCRYPT_TMTO=%u -DSCRYPT_TMP_ELEM=%" PRIu64, build_opts, hashes->salts_buf[0].scrypt_N, hashes->salts_buf[0].scrypt_r, hashes->salts_buf[0].scrypt_p, 1u << scrypt_tmto_final, (u64) scrypt_tmp_size / 16);
hc_asprintf (&build_opts_update,"%s -DSCRYPT_N=%u -DSCRYPT_R=%u -DSCRYPT_P=%u -DSCRYPT_TMTO=%u -DSCRYPT_TMP_ELEM=%" PRIu64, build_opts, hashes->salts_buf[0].scrypt_N, hashes->salts_buf[0].scrypt_r, hashes->salts_buf[0].scrypt_p, 1u << scrypt_tmto_final, (u64) scrypt_tmp_size / 16);
}
else
{
snprintf (build_opts_update, sizeof (build_opts_update) - 1, "%s", build_opts);
hc_asprintf (&build_opts_update, "%s", build_opts);
}
CL_rc = hc_clBuildProgram (hashcat_ctx, device_param->program, 1, &device_param->device, build_opts_update, NULL, NULL);

@ -304,9 +304,9 @@ void setup_environment_variables ()
if (compute)
{
static char display[100];
static char *display;
snprintf (display, sizeof (display) - 1, "DISPLAY=%s", compute);
hc_asprintf (&display, "DISPLAY=%s", compute);
putenv (display);
}

@ -255,11 +255,11 @@ const char *status_get_hash_target (const hashcat_ctx_t *hashcat_ctx)
{
if ((hashconfig->hash_mode == 2500) || (hashconfig->hash_mode == 2501))
{
char *tmp_buf = (char *) malloc (HCBUFSIZ_TINY);
char *tmp_buf;
wpa_t *wpa = (wpa_t *) hashes->esalts_buf;
snprintf (tmp_buf, HCBUFSIZ_TINY - 1, "%s (AP:%02x:%02x:%02x:%02x:%02x:%02x STA:%02x:%02x:%02x:%02x:%02x:%02x)",
hc_asprintf (&tmp_buf, "%s (AP:%02x:%02x:%02x:%02x:%02x:%02x STA:%02x:%02x:%02x:%02x:%02x:%02x)",
(char *) hashes->salts_buf[0].salt_buf,
wpa->orig_mac_ap[0],
wpa->orig_mac_ap[1],
@ -313,7 +313,7 @@ const char *status_get_hash_target (const hashcat_ctx_t *hashcat_ctx)
{
if (hashconfig->hash_mode == 3000)
{
char *tmp_buf = (char *) malloc (HCBUFSIZ_TINY);
char *tmp_buf;
char out_buf1[64] = { 0 };
char out_buf2[64] = { 0 };
@ -321,7 +321,7 @@ const char *status_get_hash_target (const hashcat_ctx_t *hashcat_ctx)
ascii_digest ((hashcat_ctx_t *) hashcat_ctx, out_buf1, sizeof (out_buf1), 0, 0);
ascii_digest ((hashcat_ctx_t *) hashcat_ctx, out_buf2, sizeof (out_buf2), 0, 1);
snprintf (tmp_buf, HCBUFSIZ_TINY - 1, "%s, %s", out_buf1, out_buf2);
hc_asprintf (&tmp_buf, "%s, %s", out_buf1, out_buf2);
return tmp_buf;
}
@ -754,14 +754,14 @@ char *status_get_guess_charset (const hashcat_ctx_t *hashcat_ctx)
if ((custom_charset_1 != NULL) || (custom_charset_2 != NULL) || (custom_charset_3 != NULL) || (custom_charset_4 != NULL))
{
char *tmp_buf = (char *) malloc (HCBUFSIZ_TINY);
char *tmp_buf;
if (custom_charset_1 == NULL) custom_charset_1 = "Undefined";
if (custom_charset_2 == NULL) custom_charset_2 = "Undefined";
if (custom_charset_3 == NULL) custom_charset_3 = "Undefined";
if (custom_charset_4 == NULL) custom_charset_4 = "Undefined";
snprintf (tmp_buf, HCBUFSIZ_TINY - 1, "-1 %s, -2 %s, -3 %s, -4 %s", custom_charset_1, custom_charset_2, custom_charset_3, custom_charset_4);
hc_asprintf (&tmp_buf, "-1 %s, -2 %s, -3 %s, -4 %s", custom_charset_1, custom_charset_2, custom_charset_3, custom_charset_4);
return tmp_buf;
}
@ -1574,7 +1574,7 @@ char *status_get_cpt (const hashcat_ctx_t *hashcat_ctx)
const hc_time_t now = hc_time (NULL);
char *cpt = (char *) malloc (HCBUFSIZ_TINY);
char *cpt;
const int cpt_cur_min = status_get_cpt_cur_min (hashcat_ctx);
const int cpt_cur_hour = status_get_cpt_cur_hour (hashcat_ctx);
@ -1586,7 +1586,7 @@ char *status_get_cpt (const hashcat_ctx_t *hashcat_ctx)
if ((cpt_ctx->cpt_start + 86400) < now)
{
snprintf (cpt, HCBUFSIZ_TINY - 1, "CUR:%d,%d,%d AVG:%d,%d,%d (Min,Hour,Day)",
hc_asprintf (&cpt, "CUR:%d,%d,%d AVG:%d,%d,%d (Min,Hour,Day)",
cpt_cur_min,
cpt_cur_hour,
cpt_cur_day,
@ -1596,7 +1596,7 @@ char *status_get_cpt (const hashcat_ctx_t *hashcat_ctx)
}
else if ((cpt_ctx->cpt_start + 3600) < now)
{
snprintf (cpt, HCBUFSIZ_TINY - 1, "CUR:%d,%d,N/A AVG:%d,%d,%d (Min,Hour,Day)",
hc_asprintf (&cpt, "CUR:%d,%d,N/A AVG:%d,%d,%d (Min,Hour,Day)",
cpt_cur_min,
cpt_cur_hour,
cpt_avg_min,
@ -1605,7 +1605,7 @@ char *status_get_cpt (const hashcat_ctx_t *hashcat_ctx)
}
else if ((cpt_ctx->cpt_start + 60) < now)
{
snprintf (cpt, HCBUFSIZ_TINY - 1, "CUR:%d,N/A,N/A AVG:%d,%d,%d (Min,Hour,Day)",
hc_asprintf (&cpt, "CUR:%d,N/A,N/A AVG:%d,%d,%d (Min,Hour,Day)",
cpt_cur_min,
cpt_avg_min,
cpt_avg_hour,
@ -1613,7 +1613,7 @@ char *status_get_cpt (const hashcat_ctx_t *hashcat_ctx)
}
else
{
snprintf (cpt, HCBUFSIZ_TINY - 1, "CUR:N/A,N/A,N/A AVG:%d,%d,%d (Min,Hour,Day)",
hc_asprintf (&cpt, "CUR:N/A,N/A,N/A AVG:%d,%d,%d (Min,Hour,Day)",
cpt_avg_min,
cpt_avg_hour,
cpt_avg_day);

Loading…
Cancel
Save