[PATCH 0/1] MR1144: msvcrt: Fix _wputenv_s invalid argument handling.
From: Piotr Caban <piotr(a)codeweavers.com> --- dlls/msvcrt/environ.c | 4 ++-- dlls/msvcrt/tests/environ.c | 39 +++++++++++++++++++++++++++++++++++-- 2 files changed, 39 insertions(+), 4 deletions(-) diff --git a/dlls/msvcrt/environ.c b/dlls/msvcrt/environ.c index 9800a1b66b1..e541bd5bff0 100644 --- a/dlls/msvcrt/environ.c +++ b/dlls/msvcrt/environ.c @@ -197,8 +197,8 @@ errno_t CDECL _wputenv_s(const wchar_t *name, const wchar_t *value) TRACE("%s %s\n", debugstr_w(name), debugstr_w(value)); - if (!MSVCRT_CHECK_PMT(name != NULL)) return -1; - if (!MSVCRT_CHECK_PMT(value != NULL)) return -1; + if (!MSVCRT_CHECK_PMT(name != NULL)) return EINVAL; + if (!MSVCRT_CHECK_PMT(value != NULL)) return EINVAL; if (!SetEnvironmentVariableW(name, value[0] ? value : NULL)) { diff --git a/dlls/msvcrt/tests/environ.c b/dlls/msvcrt/tests/environ.c index 62e4f3133cf..03129dcbf14 100644 --- a/dlls/msvcrt/tests/environ.c +++ b/dlls/msvcrt/tests/environ.c @@ -19,6 +19,7 @@ */ #include "wine/test.h" +#include <errno.h> #include <stdlib.h> #include <process.h> @@ -45,8 +46,10 @@ static const char *a_very_long_env_string = static char ***(__cdecl *p__p__environ)(void); static WCHAR ***(__cdecl *p__p__wenviron)(void); -static void (*p_get_environ)(char ***); -static void (*p_get_wenviron)(WCHAR ***); +static void (__cdecl *p_get_environ)(char ***); +static void (__cdecl *p_get_wenviron)(WCHAR ***); +static errno_t (__cdecl *p_putenv_s)(const char*, const char*); +static errno_t (__cdecl *p_wputenv_s)(const wchar_t*, const wchar_t*); static char ***p_environ; static WCHAR ***p_wenviron; @@ -61,6 +64,8 @@ static void init(void) p_wenviron = (void *)GetProcAddress(hmod, "_wenviron"); p_get_environ = (void *)GetProcAddress(hmod, "_get_environ"); p_get_wenviron = (void *)GetProcAddress(hmod, "_get_wenviron"); + p_putenv_s = (void *)GetProcAddress(hmod, "_putenv_s"); + p_wputenv_s = (void *)GetProcAddress(hmod, "_wputenv_s"); } static void test_system(void) @@ -237,6 +242,8 @@ static void test__wenviron(void) static void test_environment_manipulation(void) { + errno_t ret; + ok( _putenv("cat=") == 0, "_putenv failed on deletion of nonexistent environment variable\n" ); ok( _putenv("cat=dog") == 0, "failed setting cat=dog\n" ); ok( strcmp(getenv("cat"), "dog") == 0, "getenv did not return 'dog'\n" ); @@ -247,6 +254,34 @@ static void test_environment_manipulation(void) ok( _putenv(a_very_long_env_string) == 0, "_putenv failed for long environment string\n"); ok( getenv("nonexistent") == NULL, "getenv should fail with nonexistent var name\n" ); + + if (p_putenv_s) + { + ret = p_putenv_s(NULL, "dog"); + ok( ret == EINVAL, "_putenv_s returned %d\n", ret); + ret = p_putenv_s("cat", NULL); + ok( ret == EINVAL, "_putenv_s returned %d\n", ret); + ret = p_putenv_s("a=b", NULL); + ok( ret == EINVAL, "_putenv_s returned %d\n", ret); + ret = p_putenv_s("cat", "a=b"); + ok( !ret, "_putenv_s returned %d\n", ret); + ret = p_putenv_s("cat", ""); + ok( !ret, "_putenv_s returned %d\n", ret); + } + + if (p_wputenv_s) + { + ret = p_wputenv_s(NULL, L"dog"); + ok( ret == EINVAL, "_wputenv_s returned %d\n", ret); + ret = p_wputenv_s(L"cat", NULL); + ok( ret == EINVAL, "_wputenv_s returned %d\n", ret); + ret = p_wputenv_s(L"a=b", NULL); + ok( ret == EINVAL, "_wputenv_s returned %d\n", ret); + ret = p_wputenv_s(L"cat", L"a=b"); + ok( !ret, "_wputenv_s returned %d\n", ret); + ret = p_wputenv_s(L"cat", L""); + ok( !ret, "_wputenv_s returned %d\n", ret); + } } START_TEST(environ) -- GitLab https://gitlab.winehq.org/wine/wine/-/merge_requests/1144
Hi, It looks like your patch introduced the new failures shown below. Please investigate and fix them before resubmitting your patch. If they are not new, fixing them anyway would help a lot. Otherwise please ask for the known failures list to be updated. The full results can be found at: https://testbot.winehq.org/JobDetails.pl?Key=125299 Your paranoid android. === debian11 (build log) === Task: Could not create the win32 wineprefix: Failed to disable the crash dialogs: Task: WineTest did not produce the win32 report
participants (3)
-
Marvin -
Piotr Caban -
Piotr Caban (@piotr)