strtok() modifies the original string by replacing delimiters with \0, this can cause unintended consequences and security issues.
1#include <string.h>
2
3// Noncompliant: Insecure - Alter static literal
4void insecureUseStrtokNonCompliant() {
5 char *static_str = "message,token";
6 strtok(static_str, ",");
7}
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(©, ",", 128);
8}