...
The getenv()
function searches an environment list for a string that matches a specified name, and returns a pointer to a string associated with the matched list member. Depending on the implementation, multiple environment variables with the same name may be allowed and can cause unexpected results if a program cannot consistently choose the same value. The GNU glibc library addresses this issue in getenv()
and setenv()
by always using the first variable it encounters and ignoring the rest. Other implementations are following suit, although it is unwise to rely on this.
Running Inadvertently running a program with duplicate environment variables is a fairly simple task, as an easy error to make because the execve()
function has the signature:
...