Fix the environment functions not rejecting the empty name.

Found by musl's libc-test.
This commit is contained in:
Jonas 'Sortie' Termansen 2014-08-20 01:01:34 +02:00
parent 0adfceef87
commit 40fd0fa3dc
3 changed files with 9 additions and 0 deletions

View File

@ -39,6 +39,9 @@ extern "C" char* getenv(const char* name)
if ( !name )
return errno = EINVAL, (char*) NULL;
if ( !name[0] )
return errno = EINVAL, (char*) NULL;
// Verify the name doesn't contain a '=' character.
size_t name_length = 0;
while ( name[name_length] )

View File

@ -117,6 +117,9 @@ extern "C" int setenv(const char* name, const char* value, int overwrite)
if ( !name || !value )
return errno = EINVAL, -1;
if ( !name[0] )
return errno = EINVAL, -1;
// Verify the name doesn't contain a '=' character.
size_t name_length = 0;
while ( name[name_length] )

View File

@ -39,6 +39,9 @@ extern "C" int unsetenv(const char* name)
if ( !name )
return errno = EINVAL, -1;
if ( !name[0] )
return errno = EINVAL, -1;
// Verify the name doesn't contain a '=' character.
size_t name_length = 0;
while ( name[name_length] )