...
After the loop ends, path
is modified as follows: "/usr/bin\0/bin\0/usr/sbin\0/sbin\0"
. This is an issue because the local path
variable becomes /usr/bin
and because the environment variable PATH
has been unintentionally changed, which can have unintended consequences (see ENV30-C. Do not modify the string returned by getenv()).
Compliant Solution
In this compliant solution the string being tokenized is copied into a temporary buffer which is not referenced after the call to strtok()
:
...