1
0
mirror of https://github.com/hashcat/hashcat.git synced 2024-12-27 17:08:12 +00:00

Merge pull request #925 from neheb/master

Replace some snprintf calls with asprintf.
This commit is contained in:
Jens Steube 2016-12-21 00:39:51 +01:00 committed by GitHub
commit 1b4edc92ee
11 changed files with 35 additions and 46 deletions

View File

@ -43,11 +43,10 @@ int dictstat_init (hashcat_ctx_t *hashcat_ctx)
if (user_options->attack_mode == ATTACK_MODE_BF) return 0; if (user_options->attack_mode == ATTACK_MODE_BF) return 0;
dictstat_ctx->enabled = true; dictstat_ctx->enabled = true;
dictstat_ctx->filename = (char *) hcmalloc (HCBUFSIZ_TINY);
dictstat_ctx->base = (dictstat_t *) hccalloc (MAX_DICTSTAT, sizeof (dictstat_t)); dictstat_ctx->base = (dictstat_t *) hccalloc (MAX_DICTSTAT, sizeof (dictstat_t));
dictstat_ctx->cnt = 0; dictstat_ctx->cnt = 0;
snprintf (dictstat_ctx->filename, HCBUFSIZ_TINY - 1, "%s/hashcat.dictstat", folder_config->profile_dir); asprintf (&dictstat_ctx->filename, "%s/hashcat.dictstat", folder_config->profile_dir);
FILE *fp = fopen (dictstat_ctx->filename, "ab"); FILE *fp = fopen (dictstat_ctx->filename, "ab");

View File

@ -26,12 +26,14 @@ static int get_exec_path (char *exec_path, const size_t exec_path_sz)
{ {
#if defined (__linux__) || defined (__CYGWIN__) #if defined (__linux__) || defined (__CYGWIN__)
char tmp[32] = { 0 }; char *tmp;
snprintf (tmp, sizeof (tmp) - 1, "/proc/%d/exe", getpid ()); asprintf (&tmp, "/proc/%d/exe", getpid ());
const ssize_t len = readlink (tmp, exec_path, exec_path_sz - 1); const ssize_t len = readlink (tmp, exec_path, exec_path_sz - 1);
hcfree (tmp);
if (len == -1) return -1; if (len == -1) return -1;
#elif defined (_WIN) #elif defined (_WIN)
@ -59,8 +61,6 @@ static int get_exec_path (char *exec_path, const size_t exec_path_sz)
mib[2] = KERN_PROC_PATHNAME; mib[2] = KERN_PROC_PATHNAME;
mib[3] = -1; mib[3] = -1;
char tmp[32] = { 0 };
size_t size = exec_path_sz; size_t size = exec_path_sz;
sysctl (mib, 4, exec_path, &size, NULL, 0); sysctl (mib, 4, exec_path, &size, NULL, 0);
@ -219,9 +219,9 @@ char **scan_directory (const char *path)
if ((strncmp (de->d_name, ".", strlen (de->d_name)) == 0) || (strncmp (de->d_name, "..", strlen (de->d_name)) == 0)) continue; if ((strncmp (de->d_name, ".", strlen (de->d_name)) == 0) || (strncmp (de->d_name, "..", strlen (de->d_name)) == 0)) continue;
char *path_file = (char *) hcmalloc (HCBUFSIZ_TINY); char *path_file;
snprintf (path_file, HCBUFSIZ_TINY - 1, "%s/%s", tmp_path, de->d_name); asprintf (&path_file, "%s/%s", tmp_path, de->d_name);
DIR *d_test; DIR *d_test;
@ -389,11 +389,11 @@ int folder_config_init (hashcat_ctx_t *hashcat_ctx, MAYBE_UNUSED const char *ins
* The best workaround found so far is to modify the TMP variable (only inside hashcat process) before the runtime is load * The best workaround found so far is to modify the TMP variable (only inside hashcat process) before the runtime is load
*/ */
char *cpath = (char *) hcmalloc (HCBUFSIZ_TINY); char *cpath;
#if defined (_WIN) #if defined (_WIN)
snprintf (cpath, HCBUFSIZ_TINY - 1, "%s\\OpenCL\\", shared_dir); asprintf (&cpath, "%s\\OpenCL\\", shared_dir);
char *cpath_real = (char *) hcmalloc (HCBUFSIZ_TINY); char *cpath_real = (char *) hcmalloc (HCBUFSIZ_TINY);
@ -406,7 +406,7 @@ int folder_config_init (hashcat_ctx_t *hashcat_ctx, MAYBE_UNUSED const char *ins
#else #else
snprintf (cpath, HCBUFSIZ_TINY - 1, "%s/OpenCL/", shared_dir); asprintf (&cpath, "%s/OpenCL/", shared_dir);
char *cpath_real = (char *) hcmalloc (PATH_MAX); char *cpath_real = (char *) hcmalloc (PATH_MAX);
@ -424,9 +424,9 @@ int folder_config_init (hashcat_ctx_t *hashcat_ctx, MAYBE_UNUSED const char *ins
//if (getenv ("TMP") == NULL) //if (getenv ("TMP") == NULL)
if (1) if (1)
{ {
char tmp[1000]; char *tmp;
snprintf (tmp, sizeof (tmp) - 1, "TMP=%s", cpath_real); asprintf (&tmp, "TMP=%s", cpath_real);
putenv (tmp); putenv (tmp);
} }
@ -448,9 +448,9 @@ int folder_config_init (hashcat_ctx_t *hashcat_ctx, MAYBE_UNUSED const char *ins
* kernel cache, we need to make sure folder exist * kernel cache, we need to make sure folder exist
*/ */
char *kernels_folder = (char *) hcmalloc (HCBUFSIZ_TINY); char *kernels_folder;
snprintf (kernels_folder, HCBUFSIZ_TINY - 1, "%s/kernels", profile_dir); asprintf (&kernels_folder, "%s/kernels", profile_dir);
hc_mkdir (kernels_folder, 0700); hc_mkdir (kernels_folder, 0700);

View File

@ -55,9 +55,9 @@ static char *hm_SYSFS_get_syspath_device (hashcat_ctx_t *hashcat_ctx, const int
hc_device_param_t *device_param = &opencl_ctx->devices_param[device_id]; hc_device_param_t *device_param = &opencl_ctx->devices_param[device_id];
char *syspath = hcmalloc (HCBUFSIZ_TINY); char *syspath;
snprintf (syspath, HCBUFSIZ_TINY - 1, "%s/0000:%02x:%02x.%01x", SYS_BUS_PCI_DEVICES, device_param->pcie_bus, device_param->pcie_device, device_param->pcie_function); asprintf (&syspath, "%s/0000:%02x:%02x.%01x", SYS_BUS_PCI_DEVICES, device_param->pcie_bus, device_param->pcie_device, device_param->pcie_function);
return syspath; return syspath;
} }

View File

@ -48,9 +48,9 @@ int induct_ctx_init (hashcat_ctx_t *hashcat_ctx)
if (user_options->induction_dir == NULL) if (user_options->induction_dir == NULL)
{ {
char *root_directory = (char *) hcmalloc (HCBUFSIZ_TINY); char *root_directory;
snprintf (root_directory, HCBUFSIZ_TINY - 1, "%s/%s.%s", folder_config->session_dir, user_options->session, INDUCT_DIR); asprintf (&root_directory, "%s/%s.%s", folder_config->session_dir, user_options->session, INDUCT_DIR);
if (rmdir (root_directory) == -1) if (rmdir (root_directory) == -1)
{ {
@ -60,9 +60,9 @@ int induct_ctx_init (hashcat_ctx_t *hashcat_ctx)
} }
else if (errno == ENOTEMPTY) else if (errno == ENOTEMPTY)
{ {
char *root_directory_mv = (char *) hcmalloc (HCBUFSIZ_TINY); char *root_directory_mv;
snprintf (root_directory_mv, HCBUFSIZ_TINY - 1, "%s/%s.induct.%d", folder_config->session_dir, user_options->session, (int) time (NULL)); asprintf (&root_directory_mv, "%s/%s.induct.%d", folder_config->session_dir, user_options->session, (int) time (NULL));
if (rename (root_directory, root_directory_mv) != 0) if (rename (root_directory, root_directory_mv) != 0)
{ {
@ -70,6 +70,8 @@ int induct_ctx_init (hashcat_ctx_t *hashcat_ctx)
return -1; return -1;
} }
hcfree (root_directory_mv);
} }
else else
{ {

View File

@ -83,9 +83,7 @@ int logfile_init (hashcat_ctx_t *hashcat_ctx)
if (user_options->logfile_disable == true) return 0; if (user_options->logfile_disable == true) return 0;
logfile_ctx->logfile = (char *) hcmalloc (HCBUFSIZ_TINY); asprintf (&logfile_ctx->logfile, "%s/%s.log", folder_config->session_dir, user_options->session);
snprintf (logfile_ctx->logfile, HCBUFSIZ_TINY - 1, "%s/%s.log", folder_config->session_dir, user_options->session);
logfile_ctx->subid = (char *) hcmalloc (HCBUFSIZ_TINY); logfile_ctx->subid = (char *) hcmalloc (HCBUFSIZ_TINY);
logfile_ctx->topid = (char *) hcmalloc (HCBUFSIZ_TINY); logfile_ctx->topid = (char *) hcmalloc (HCBUFSIZ_TINY);

View File

@ -102,7 +102,7 @@ int loopback_write_open (hashcat_ctx_t *hashcat_ctx)
const u32 random_num = get_random_num (0, 9999); const u32 random_num = get_random_num (0, 9999);
snprintf (loopback_ctx->filename, HCBUFSIZ_TINY - 1, "%s/%s.%d_%u", induct_ctx->root_directory, LOOPBACK_FILE, (int) now, random_num); asprintf (&loopback_ctx->filename, "%s/%s.%d_%u", induct_ctx->root_directory, LOOPBACK_FILE, (int) now, random_num);
FILE *fp = fopen (loopback_ctx->filename, "ab"); FILE *fp = fopen (loopback_ctx->filename, "ab");

View File

@ -339,9 +339,7 @@ int outcheck_ctx_init (hashcat_ctx_t *hashcat_ctx)
if (user_options->outfile_check_dir == NULL) if (user_options->outfile_check_dir == NULL)
{ {
outcheck_ctx->root_directory = (char *) hcmalloc (HCBUFSIZ_TINY); asprintf (&outcheck_ctx->root_directory, "%s/%s.%s", folder_config->session_dir, user_options->session, OUTFILES_DIR);
snprintf (outcheck_ctx->root_directory, HCBUFSIZ_TINY - 1, "%s/%s.%s", folder_config->session_dir, user_options->session, OUTFILES_DIR);
} }
else else
{ {

View File

@ -97,10 +97,9 @@ int potfile_init (hashcat_ctx_t *hashcat_ctx)
if (user_options->potfile_path == NULL) if (user_options->potfile_path == NULL)
{ {
potfile_ctx->filename = (char *) hcmalloc (HCBUFSIZ_TINY);
potfile_ctx->fp = NULL; potfile_ctx->fp = NULL;
snprintf (potfile_ctx->filename, HCBUFSIZ_TINY - 1, "%s/hashcat.potfile", folder_config->profile_dir); asprintf (&potfile_ctx->filename, "%s/hashcat.potfile", folder_config->profile_dir);
} }
else else
{ {

View File

@ -47,9 +47,9 @@ static int check_running_process (hashcat_ctx_t *hashcat_ctx)
{ {
#if defined (_POSIX) #if defined (_POSIX)
char *pidbin = (char *) hcmalloc (HCBUFSIZ_LARGE); char *pidbin;
snprintf (pidbin, HCBUFSIZ_LARGE - 1, "/proc/%u/cmdline", rd->pid); asprintf (&pidbin, "/proc/%u/cmdline", rd->pid);
FILE *fd = fopen (pidbin, "rb"); FILE *fd = fopen (pidbin, "rb");
@ -356,18 +356,13 @@ int restore_ctx_init (hashcat_ctx_t *hashcat_ctx, int argc, char **argv)
if (user_options->restore_file_path == NULL) if (user_options->restore_file_path == NULL)
{ {
restore_ctx->eff_restore_file = (char *) hcmalloc (HCBUFSIZ_TINY); asprintf (&restore_ctx->eff_restore_file, "%s/%s.restore", folder_config->session_dir, user_options->session);
restore_ctx->new_restore_file = (char *) hcmalloc (HCBUFSIZ_TINY); asprintf (&restore_ctx->new_restore_file, "%s/%s.restore.new", folder_config->session_dir, user_options->session);
snprintf (restore_ctx->eff_restore_file, HCBUFSIZ_TINY - 1, "%s/%s.restore", folder_config->session_dir, user_options->session);
snprintf (restore_ctx->new_restore_file, HCBUFSIZ_TINY - 1, "%s/%s.restore.new", folder_config->session_dir, user_options->session);
} }
else else
{ {
restore_ctx->eff_restore_file = hcstrdup (user_options->restore_file_path); restore_ctx->eff_restore_file = hcstrdup (user_options->restore_file_path);
restore_ctx->new_restore_file = (char *) hcmalloc (HCBUFSIZ_TINY); asprintf (&restore_ctx->new_restore_file, "%s.new", user_options->restore_file_path);
snprintf (restore_ctx->new_restore_file, HCBUFSIZ_TINY - 1, "%s.new", user_options->restore_file_path);
} }
restore_ctx->argc = argc; restore_ctx->argc = argc;

View File

@ -67,9 +67,9 @@ int tuning_db_init (hashcat_ctx_t *hashcat_ctx)
tuning_db->enabled = true; tuning_db->enabled = true;
char *tuning_db_file = (char *) hcmalloc (HCBUFSIZ_TINY); char *tuning_db_file;
snprintf (tuning_db_file, HCBUFSIZ_TINY - 1, "%s/%s", folder_config->shared_dir, TUNING_DB_FILE); asprintf (&tuning_db_file, "%s/%s", folder_config->shared_dir, TUNING_DB_FILE);
FILE *fp = fopen (tuning_db_file, "rb"); FILE *fp = fopen (tuning_db_file, "rb");

View File

@ -22,8 +22,7 @@ u32 convert_from_hex (hashcat_ctx_t *hashcat_ctx, char *line_buf, const u32 line
if (user_options->hex_wordlist == true) if (user_options->hex_wordlist == true)
{ {
u32 i; size_t i, j;
u32 j;
for (i = 0, j = 0; j < line_len; i += 1, j += 2) for (i = 0, j = 0; j < line_len; i += 1, j += 2)
{ {
@ -44,8 +43,7 @@ u32 convert_from_hex (hashcat_ctx_t *hashcat_ctx, char *line_buf, const u32 line
if (line_buf[4] != '[') return (line_len); if (line_buf[4] != '[') return (line_len);
if (line_buf[line_len - 1] != ']') return (line_len); if (line_buf[line_len - 1] != ']') return (line_len);
u32 i; size_t i, j;
u32 j;
for (i = 0, j = 5; j < line_len - 1; i += 1, j += 2) for (i = 0, j = 5; j < line_len - 1; i += 1, j += 2)
{ {