1
0
mirror of https://github.com/hashcat/hashcat.git synced 2024-11-13 19:28:56 +00:00

Replaced all calls to strtok() with strtok_r() to ensure thread safety

This commit is contained in:
jsteube 2016-11-16 10:35:01 +01:00
parent 316694fd08
commit 536dcef7eb
4 changed files with 32 additions and 16 deletions

View File

@ -59,7 +59,9 @@ int set_cpu_affinity (hashcat_ctx_t *hashcat_ctx)
char *devices = hcstrdup (hashcat_ctx, user_options->cpu_affinity);
char *next = strtok (devices, ",");
char *saveptr = NULL;
char *next = strtok_r (devices, ",", &saveptr);
do
{
@ -89,7 +91,7 @@ int set_cpu_affinity (hashcat_ctx_t *hashcat_ctx)
CPU_SET ((cpu_id - 1), &cpuset);
#endif
} while ((next = strtok (NULL, ",")) != NULL);
} while ((next = strtok_r (NULL, ",", &saveptr)) != NULL);
hcfree (devices);

View File

@ -4805,7 +4805,9 @@ int ikepsk_md5_parse_hash (u8 *input_buf, u32 input_len, hash_t *hash_buf, MAYBE
size_t in_len[9] = { 0 };
in_off[0] = (u8 *) strtok ((char *) input_buf, ":");
char *saveptr = NULL;
in_off[0] = (u8 *) strtok_r ((char *) input_buf, ":", &saveptr);
if (in_off[0] == NULL) return (PARSER_SEPARATOR_UNMATCHED);
@ -4815,7 +4817,7 @@ int ikepsk_md5_parse_hash (u8 *input_buf, u32 input_len, hash_t *hash_buf, MAYBE
for (i = 1; i < 9; i++)
{
in_off[i] = (u8 *) strtok ((char *) NULL, ":");
in_off[i] = (u8 *) strtok_r ((char *) NULL, ":", &saveptr);
if (in_off[i] == NULL) return (PARSER_SEPARATOR_UNMATCHED);
@ -4892,7 +4894,9 @@ int ikepsk_sha1_parse_hash (u8 *input_buf, u32 input_len, hash_t *hash_buf, MAYB
size_t in_len[9] = { 0 };
in_off[0] = (u8 *) strtok ((char *) input_buf, ":");
char *saveptr = NULL;
in_off[0] = (u8 *) strtok_r ((char *) input_buf, ":", &saveptr);
if (in_off[0] == NULL) return (PARSER_SEPARATOR_UNMATCHED);
@ -4902,7 +4906,7 @@ int ikepsk_sha1_parse_hash (u8 *input_buf, u32 input_len, hash_t *hash_buf, MAYB
for (i = 1; i < 9; i++)
{
in_off[i] = (u8 *) strtok ((char *) NULL, ":");
in_off[i] = (u8 *) strtok_r ((char *) NULL, ":", &saveptr);
if (in_off[i] == NULL) return (PARSER_SEPARATOR_UNMATCHED);
@ -20127,7 +20131,9 @@ int hashconfig_general_defaults (hashcat_ctx_t *hashcat_ctx)
char *keyfiles = hcstrdup (hashcat_ctx, tcvc_keyfiles);
char *keyfile = strtok (keyfiles, ",");
char *saveptr = NULL;
char *keyfile = strtok_r (keyfiles, ",", &saveptr);
do
{
@ -20135,7 +20141,7 @@ int hashconfig_general_defaults (hashcat_ctx_t *hashcat_ctx)
if (rc_crc32 == -1) return -1;
} while ((keyfile = strtok (NULL, ",")) != NULL);
} while ((keyfile = strtok_r (NULL, ",", &saveptr)) != NULL);
free (keyfiles);
}

View File

@ -176,7 +176,9 @@ static int setup_opencl_platforms_filter (hashcat_ctx_t *hashcat_ctx, const char
{
char *platforms = hcstrdup (hashcat_ctx, opencl_platforms);
char *next = strtok (platforms, ",");
char *saveptr = NULL;
char *next = strtok_r (platforms, ",", &saveptr);
do
{
@ -191,7 +193,7 @@ static int setup_opencl_platforms_filter (hashcat_ctx_t *hashcat_ctx, const char
opencl_platforms_filter |= 1u << (platform - 1);
} while ((next = strtok (NULL, ",")) != NULL);
} while ((next = strtok_r (NULL, ",", &saveptr)) != NULL);
hcfree (platforms);
}
@ -213,7 +215,9 @@ static int setup_devices_filter (hashcat_ctx_t *hashcat_ctx, const char *opencl_
{
char *devices = hcstrdup (hashcat_ctx, opencl_devices);
char *next = strtok (devices, ",");
char *saveptr = NULL;
char *next = strtok_r (devices, ",", &saveptr);
do
{
@ -228,7 +232,7 @@ static int setup_devices_filter (hashcat_ctx_t *hashcat_ctx, const char *opencl_
devices_filter |= 1u << (device_id - 1);
} while ((next = strtok (NULL, ",")) != NULL);
} while ((next = strtok_r (NULL, ",", &saveptr)) != NULL);
hcfree (devices);
}
@ -250,7 +254,9 @@ static int setup_device_types_filter (hashcat_ctx_t *hashcat_ctx, const char *op
{
char *device_types = hcstrdup (hashcat_ctx, opencl_device_types);
char *next = strtok (device_types, ",");
char *saveptr = NULL;
char *next = strtok_r (device_types, ",", &saveptr);
do
{
@ -265,7 +271,7 @@ static int setup_device_types_filter (hashcat_ctx_t *hashcat_ctx, const char *op
device_types_filter |= 1u << device_type;
} while ((next = strtok (NULL, ",")) != NULL);
} while ((next = strtok_r (NULL, ",", &saveptr)) != NULL);
hcfree (device_types);
}

View File

@ -118,13 +118,15 @@ int tuning_db_init (hashcat_ctx_t *hashcat_ctx)
int token_cnt = 0;
char *next = strtok (line_buf, "\t ");
char *saveptr = NULL;
char *next = strtok_r (line_buf, "\t ", &saveptr);
token_ptr[token_cnt] = next;
token_cnt++;
while ((next = strtok (NULL, "\t ")) != NULL)
while ((next = strtok_r (NULL, "\t ", &saveptr)) != NULL)
{
token_ptr[token_cnt] = next;