diff --git a/libc/stdlib/getenv.cpp b/libc/stdlib/getenv.cpp index 1b489199..1e621462 100644 --- a/libc/stdlib/getenv.cpp +++ b/libc/stdlib/getenv.cpp @@ -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] ) diff --git a/libc/stdlib/setenv.cpp b/libc/stdlib/setenv.cpp index 2fad106b..335abdbb 100644 --- a/libc/stdlib/setenv.cpp +++ b/libc/stdlib/setenv.cpp @@ -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] ) diff --git a/libc/stdlib/unsetenv.cpp b/libc/stdlib/unsetenv.cpp index 9395feaa..243594ff 100644 --- a/libc/stdlib/unsetenv.cpp +++ b/libc/stdlib/unsetenv.cpp @@ -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] )