From 399b08aa9f02362a14f8d2975ac7f70b91bb0963 Mon Sep 17 00:00:00 2001 From: jBarz Date: Thu, 9 Mar 2017 09:32:25 -0500 Subject: [PATCH] unix: return UV_EINVAL for NULL env name MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit "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 Reviewed-By: Santiago Gimeno Reviewed-By: Saúl Ibarra Corretgé --- src/unix/core.c | 2 +- test/test-env-vars.c | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/src/unix/core.c b/src/unix/core.c index 2a7a6420..96495b86 100644 --- a/src/unix/core.c +++ b/src/unix/core.c @@ -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) diff --git a/test/test-env-vars.c b/test/test-env-vars.c index 7aa5881a..641050e6 100644 --- a/test/test-env-vars.c +++ b/test/test-env-vars.c @@ -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;