Insecure use strtok function High

strtok() modifies the original string by replacing delimiters with \0, this can cause unintended consequences and security issues.

Detector ID
c/insecure-use-strtok-fn@v1.0
Category
Common Weakness Enumeration (CWE) external icon
Tags
-

Noncompliant example

1#include <string.h>
2
3// Noncompliant: Insecure - Alter static literal
4void insecureUseStrtokNonCompliant() {
5    char *static_str = "message,token";
6    strtok(static_str, ",");
7}

Compliant example

1#include <string.h>
2
3// Compliant: Secure - Copy first
4int insecureUseStrtokCompliant() {
5  char *static_str = "message,token";
6  char copy[128];
7  strsep_s(&copy, ",", 128);
8}