DragonFly bugs List (threaded) for 2009-04
DragonFly BSD
DragonFly bugs List (threaded) for 2009-04
[Date Prev][Date Next]  [Thread Prev][Thread Next]  [Date Index][Thread Index]

[issue1341] printenv(1): don't allow '=' in name


From: "Stathis Kamperis \(via DragonFly issue tracker\)" <sinknull@xxxxxxxxxxxxxxxxxxxxxxx>
Date: Mon, 20 Apr 2009 16:48:06 +0000

Stathis Kamperis <ekamperi@gmail.com> added the comment:

: If the environment variable isn't supposed to exist then it won't find it.
: If the environment variable does exist it is not printenv's job to check
: whether it is legal or not.

True, but printenv isn't very good at deciding if a variable exists in an
environment or not, in case the name contains an '='.

Here is an example. Let's say that there is a variable named "foo" that equals
"bar=123" and we ask from printenv to print the variable "foo=bar" (which
obviously doesn't exist). Here is what happens: 

For every "name=value" pair inside the environment, printenv invokes a memcmp
between the currently examined variable and the target, of at most `len' bytes.
Where `len' is the length of the target. So, memcmp("foo=bar", "foo=bar=123", 7)
actually returns a match, although "foo=bar" doesn't correspond to a real variable.

I hope I didn't confuse things more.

Cheers,
Stathis

_____________________________________________________
DragonFly issue tracker <bugs@lists.dragonflybsd.org>
<http://bugs.dragonflybsd.org/issue1341>
_____________________________________________________



[Date Prev][Date Next]  [Thread Prev][Thread Next]  [Date Index][Thread Index]