Replace some snprintf calls with asprintf.
Simplifies the code.
This commit is contained in:
+13
-13
@@ -26,12 +26,14 @@ static int get_exec_path (char *exec_path, const size_t exec_path_sz)
|
||||
{
|
||||
#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);
|
||||
|
||||
hcfree (tmp);
|
||||
|
||||
if (len == -1) return -1;
|
||||
|
||||
#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[3] = -1;
|
||||
|
||||
char tmp[32] = { 0 };
|
||||
|
||||
size_t size = exec_path_sz;
|
||||
|
||||
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;
|
||||
|
||||
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;
|
||||
|
||||
@@ -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
|
||||
*/
|
||||
|
||||
char *cpath = (char *) hcmalloc (HCBUFSIZ_TINY);
|
||||
char *cpath;
|
||||
|
||||
#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);
|
||||
|
||||
@@ -406,7 +406,7 @@ int folder_config_init (hashcat_ctx_t *hashcat_ctx, MAYBE_UNUSED const char *ins
|
||||
|
||||
#else
|
||||
|
||||
snprintf (cpath, HCBUFSIZ_TINY - 1, "%s/OpenCL/", shared_dir);
|
||||
asprintf (&cpath, "%s/OpenCL/", shared_dir);
|
||||
|
||||
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 (1)
|
||||
{
|
||||
char tmp[1000];
|
||||
char *tmp;
|
||||
|
||||
snprintf (tmp, sizeof (tmp) - 1, "TMP=%s", cpath_real);
|
||||
asprintf (&tmp, "TMP=%s", cpath_real);
|
||||
|
||||
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
|
||||
*/
|
||||
|
||||
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);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user