Remove all strtok uses and replace them by strtok_r.
Do the same for Windows builds. Cygwin builds fine with strtok_r.
Add strtok to banned function list.
position p1;
@@
-\(sprintf@i\|strcat@i\|strcpy@i\|strncpy@i\|strncat@i\|strndup@i\|strchrdup@i\)(...)@p1
+\(strtok@i\|sprintf@i\|strcat@i\|strcpy@i\|strncpy@i\|strncat@i\|strndup@i\|strchrdup@i\)(...)@p1
@script:python@
p1 << banned.p1;
uint32_t abs_off = 0;
int32_t rel_off = 0;
uint8_t flags = 0;
+ char *saveptr = NULL;
- tok = strtok(asn1str, ASN_DELIM);
+ tok = strtok_r(asn1str, ASN_DELIM, &saveptr);
if (tok == NULL) {
SCLogError(SC_ERR_INVALID_VALUE, "Malformed asn1 argument: %s",
asn1str);
} else if (strcasecmp("oversize_length", tok) == 0) {
flags |= ASN1_OVERSIZE_LEN;
/* get the param */
- tok = strtok(NULL, ASN_DELIM);
+ tok = strtok_r(NULL, ASN_DELIM, &saveptr);
if ( tok == NULL ||
ByteExtractStringUint32(&ov_len, 10, 0, tok) <= 0)
{
} else if (strcasecmp("absolute_offset", tok) == 0) {
flags |= ASN1_ABSOLUTE_OFFSET;
/* get the param */
- tok = strtok(NULL, ASN_DELIM);
+ tok = strtok_r(NULL, ASN_DELIM, &saveptr);
if (tok == NULL ||
ByteExtractStringUint32(&abs_off, 10, 0, tok) <= 0)
{
} else if (strcasecmp("relative_offset",tok) == 0) {
flags |= ASN1_RELATIVE_OFFSET;
/* get the param */
- tok = strtok(NULL, ASN_DELIM);
+ tok = strtok_r(NULL, ASN_DELIM, &saveptr);
if (tok == NULL ||
ByteExtractStringInt32(&rel_off, 10, 0, tok) <= 0)
{
asn1str);
return NULL;
}
- tok = strtok(NULL, ASN_DELIM);
+ tok = strtok_r(NULL, ASN_DELIM, &saveptr);
}
fd = SCMalloc(sizeof(DetectAsn1Data));
int seconds_pos = 0, count_pos = 0;
uint16_t pos = 0;
int i = 0;
+ char *saveptr = NULL;
copy_str = SCStrdup(rawstr);
if (unlikely(copy_str == NULL)) {
goto error;
}
- for(pos = 0, df_opt = strtok(copy_str,","); pos < strlen(copy_str) && df_opt != NULL; pos++, df_opt = strtok(NULL,",")) {
-
+ for (pos = 0, df_opt = strtok_r(copy_str,",", &saveptr);
+ pos < strlen(copy_str) && df_opt != NULL;
+ pos++, df_opt = strtok_r(NULL,",", &saveptr))
+ {
if(strstr(df_opt,"count"))
count_found++;
if(strstr(df_opt,"second"))
goto error;
}
- for(pos = 0, threshold_opt = strtok(copy_str,","); pos < strlen(copy_str) && threshold_opt != NULL; pos++, threshold_opt = strtok(NULL,",")) {
-
+ char *saveptr = NULL;
+ for (pos = 0, threshold_opt = strtok_r(copy_str,",", &saveptr);
+ pos < strlen(copy_str) && threshold_opt != NULL;
+ pos++, threshold_opt = strtok_r(NULL,"," , &saveptr))
+ {
if(strstr(threshold_opt,"count"))
count_found++;
if(strstr(threshold_opt,"second"))
FILE *fp = fopen(PROTO_FILE,"r");
if (fp != NULL) {
char line[200];
-#if !defined(__WIN32) && !defined(_WIN32)
char *ptr = NULL;
-#endif /* __WIN32 */
while(fgets(line, sizeof(line), fp) != NULL) {
if (line[0] == '#')
continue;
-#if defined(__WIN32) || defined(_WIN32)
- char *name = strtok(line," \t");
-#else
char *name = strtok_r(line," \t", &ptr);
-#endif /* __WIN32 */
if (name == NULL)
continue;
-#if defined(__WIN32) || defined(_WIN32)
- char *proto_ch = strtok(NULL," \t");
-#else
char *proto_ch = strtok_r(NULL," \t", &ptr);
-#endif /* __WIN32 */
if (proto_ch == NULL)
continue;
if (proto >= 255)
continue;
-#if defined(__WIN32) || defined(_WIN32)
- char *cname = strtok(NULL, " \t");
-#else
char *cname = strtok_r(NULL, " \t", &ptr);
-#endif /* __WIN32 */
if (known_proto[proto] != NULL) {
SCFree(known_proto[proto]);