unix: return UV_EINVAL for NULL env name

"setenv" on z/OS returns successfully on a NULL ptr argument
for name. Check for this on all unixes.

PR-URL: https://github.com/libuv/libuv/pull/1243
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Santiago Gimeno <santiago.gimeno@gmail.com>
Reviewed-By: Saúl Ibarra Corretgé <saghul@gmail.com>
This commit is contained in:
jBarz 2017-03-09 09:32:25 -05:00 committed by Saúl Ibarra Corretgé
parent c4bd9f48e0
commit 399b08aa9f
2 changed files with 3 additions and 1 deletions

View File

@ -1269,7 +1269,7 @@ int uv_os_getenv(const char* name, char* buffer, size_t* size) {
int uv_os_setenv(const char* name, const char* value) {
if (value == NULL)
if (name == NULL || value == NULL)
return -EINVAL;
if (setenv(name, value, 1) != 0)

View File

@ -36,6 +36,8 @@ TEST_IMPL(env_vars) {
ASSERT(r == UV_EINVAL);
r = uv_os_setenv(name, NULL);
ASSERT(r == UV_EINVAL);
r = uv_os_setenv(NULL, NULL);
ASSERT(r == UV_EINVAL);
/* Reject invalid inputs when retrieving an environment variable */
size = BUF_SIZE;