Fix Issue 13367 - Buffer overflow when setting PATH

Fixup for pull #2332.
Merge pull request #2459 from denis-sh/fix-temp-c-string-allocation

Fix Issue 13367 - Buffer overflow when setting PATH