Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Even if your platform assumes that $PATH is defined, defines PATH_MAX, and enforces that paths not have more than PATH_MAX characters, the $PATH environment variable still is not required to have less than PATH_MAX chars. And if it has more than PATH_MAX chars, a buffer overflow will result. Also, if $PATH is not defined, then strcpy() will attempt to dereference a null pointer.

Compliant Solution

In the following this compliant solution, the strlen() function is used to calculate the size of the string, and the required space is dynamically allocated:

...