From 536dcef7eb9f41a22cc3df35faef5aa8cd6a9388 Mon Sep 17 00:00:00 2001 From: jsteube Date: Wed, 16 Nov 2016 10:35:01 +0100 Subject: [PATCH] Replaced all calls to strtok() with strtok_r() to ensure thread safety --- src/affinity.c | 6 ++++-- src/interface.c | 18 ++++++++++++------ src/opencl.c | 18 ++++++++++++------ src/tuningdb.c | 6 ++++-- 4 files changed, 32 insertions(+), 16 deletions(-) diff --git a/src/affinity.c b/src/affinity.c index db9c97aa8..8f0ef9107 100644 --- a/src/affinity.c +++ b/src/affinity.c @@ -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); diff --git a/src/interface.c b/src/interface.c index f517afe5f..c30c61c0f 100644 --- a/src/interface.c +++ b/src/interface.c @@ -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); } diff --git a/src/opencl.c b/src/opencl.c index c2657bdcc..a0cc3516e 100644 --- a/src/opencl.c +++ b/src/opencl.c @@ -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); } diff --git a/src/tuningdb.c b/src/tuningdb.c index 9153d53b1..84a05408e 100644 --- a/src/tuningdb.c +++ b/src/tuningdb.c @@ -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;