If I am correct, the environment of a process is an array of strings. The strings usually have the form "name=value", but not necessarily. I was wondering for what purposes the strings don't have the "name=value" form? Thanks.

  • 2
    Can you give such an example? – Kusalananda Apr 16 '18 at 13:18
  • When your program calls execve() to execute a program, you can give whatever strings to the env argument. It is up to the program being invoked to interpret the environment strings. But I haven't seen such example. – Tim Apr 16 '18 at 13:20
  • Isn't name=value the shell's way of assigning values? Seeing a counterexample would clarify what you're asking about. – Jeff Schaller Apr 16 '18 at 13:26
  • 2
    I had an example of another different case, but the question has been closed. – JdeBP Apr 17 '18 at 18:25
  • 3
    I can't understand the close reason, this question perfectly clear to me. Reviewers: Please read the answer, then vote for reopen. – peterh - Reinstate Monica Apr 17 '18 at 19:20

I'm not aware of anything actually using or expecting environment strings that don't contain =. Those would typically be pathological cases.

GNU env or printenv will faithfully print them.

For some languages, those strings will be out of reach. For instance, if you call perl with a foo env string, it won't show in keys(%ENV), though perl would still pass it along to the commands it executes (unless you reset the whole %ENV hash).

So one could possibly use that to bypass some environment sanitizing (though proper environment sanitizing should start with an empty environment).

Some tools (like some shells) strip them from the environment they receive and don't pass them along to commands they execute, so in general it's not a good idea to rely on that.

Beside the =-less env strings, other pathological cases include env strings with duplicate variable name (like both foo=good and foo=bad passed in envp) which has already been seen as causing vulnerabilities (like CVE-2016-2381), and env strings like =foo (empty variable name; note that POSIX putenv()/getenv() can set/get that variable, but not setenv()).

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.