This is the mail archive of the libc-alpha@sources.redhat.com mailing list for the glibc 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(), unsetenv() and '=' in name argument


Gidday,

The SUSv3 specification for setenv() and unsetenv() stipulates that 
the name argument to setenv() and unsetenv() may not contain an '='
character -- the error EINVAL should result.  However, as currently 
implemented glibc permits an '=' for name in both of these functions.
Aside from the violation of the standard, this can lead to strangeness.
For example, if we do a:

setenv("XXX=yyy", "222");

then we can do:

    getenv("XXX=yyy"), which returns "222"

and

    getenv("XXX"), which also (!) returns "222"

It is of course just a matter of adding code like:

    if (strchr(name, '=') != NULL) {
        errno == EINVAL;
        return -1;
    }

to both setenv() and unsetenv().

(The implication of the above getenv() calls is that probably the 
treatment of '=' needs to be cleaned up in getenv() and putenv()
also, although SUSv3 is not precise on this point: for putenv() it 
just says that the argument should be of the form "name=value"; for
getenv(), no mention is made of the handling of '=', but the glibc 
behaviour above definitely seems strange.)

Cheers,

Michael

-- 
Michael Kerrisk
mtk-lists@gmx.net

+++ Jetzt WLAN-Router für alle DSL-Einsteiger und Wechsler +++
GMX DSL-Powertarife zudem 3 Monate gratis* http://www.gmx.net/dsl


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