This is the mail archive of the glibc-bugs@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]

[Bug libc/283] New: POSIX.1-2001: setenv called with envname containing = should fail


Reference 1003.1, 2004 edition p1306 l40983
If the envname argument points to a string containing an "=" character
then setenv() shall fail and set errno to EINVAL.

The following code checks that an environment variable "ENVVAR" is not
set and then calls setenv() with the envname argument "ENVVAR="
and the envval argument to to "VALUE2", it should fail returning
-1 and setting EINVAL but succeeds and sets the environment
variable to the value "=VALUE2"

#include <stdlib.h>
#include <stdio.h>
#include <errno.h>

main()
{
int ret;
int err;
errno=0;
 
/* get the value */
printf ("Check that ENVVAR is not set in the environment\n");
printf ("ENVVAR expected \"(null)\" got \"%s\"\n", getenv("ENVVAR"));
 
/* set an environment name containing an = character */
printf ("call setenv() with envname set to \"ENVVAR=\" and envval set to
\"VALUE2\"\n");
errno=0;
ret=setenv("ENVVAR=", "VALUE2", 1);
/* should fail*/
err=errno;
if (ret != -1)
   {
        printf("setenv FAIL:expected to fail since envname contain an =
character\n");
        printf("errno=%d, expected EINVAL\n", err);
   }
printf ("ENVVAR expected \"(null)\" got \"%s\"\n", getenv("ENVVAR"));
 
}
 
$ make CC=c99 CFLAGS=-D_POSIX_C_SOURCE=200112L setenv
make: `setenv' is up to date.
-sh-2.05b$ ./setenv
Check that ENVVAR is not set in the environment
ENVVAR expected "(null)" got "(null)"
call setenv() with envname set to "ENVVAR=" and envval set to "VALUE2"
setenv FAIL:expected to fail since envname contain an = character
errno=0, expected EINVAL
ENVVAR expected "(null)" got "=VALUE2"

-- 
           Summary: POSIX.1-2001: setenv called with envname containing =
                    should fail
           Product: glibc
           Version: 2.3.2
            Status: NEW
          Severity: normal
          Priority: P2
         Component: libc
        AssignedTo: gotom at debian dot or dot jp
        ReportedBy: a dot josey at opengroup dot org
                CC: glibc-bugs at sources dot redhat dot com


http://sources.redhat.com/bugzilla/show_bug.cgi?id=283

------- You are receiving this mail because: -------
You are on the CC list for the bug, or are watching someone who is.


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