This is the mail archive of the mailing list for the newlib project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

setenv problems


while looking through the cegcc project, I discovered a few issues
with the setenv() (_setenv_r) and getenv() (_getenv_r) functions:

1. In the beginning of the function, the pointer to the value string
is shifted if the string starts with '='. The comment says that is to
prevent values to start from '='. I couldn't find anywhere in the
definition of setenv() that a value may not start with equal
character. Any reason for eating first equal character up?

2. The setenv() man pages seem to ask for returning EINVAL in case
there is an equal character inside the name of the variable. It also
says that glibc versions do allow to have environment variable names
with equal signs in them, however, the current implementation of
environment variables in newlib doesn't seem to be able to distinguish
between those. (So, if you set variable named (a=b) with value (c),
the getenv for (a) will return (b=c)). So I believe newlibs setenv
should return EINVAL.

3. The getenv() implementation searches for the variables that have
the name as passed, unless the name contains an equal sign in it, in
which case, the only part that is searched for is the characters
before the equal sign. So if you call setenv("foo", "bar", 1) and then
call getenv("foo=grape"), you will get "foo=bar" as the result of that
getenv call.

Since cegcc project uses newlib for base library support, I'm
cross-posting to both lists. Would appreciate any comments on the
above. I can produce a patch that restricts both functions to POSIX


With best of best regards
Pawel S. Veselov

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]