From ff531eaade5506a75397af93bc00024a0d3bec64 Mon Sep 17 00:00:00 2001 From: Katayama Hirofumi MZ Date: Mon, 8 Apr 2024 09:17:08 +0900 Subject: [PATCH] [SHLWAPI][SHLWAPI_APITEST] Fix NULL behavior of StrDupA/W (#6720) Fix wrong behavior of shlwapi!StrDupA and shlwapi!StrDupW functions. JIRA issue: CORE-19495 Return NULL when lpszStr == NULL. --- dll/win32/shlwapi/string.c | 8 ++++ .../rostests/apitests/shlwapi/CMakeLists.txt | 1 + modules/rostests/apitests/shlwapi/StrDup.c | 46 +++++++++++++++++++ modules/rostests/apitests/shlwapi/testlist.c | 2 + 4 files changed, 57 insertions(+) create mode 100644 modules/rostests/apitests/shlwapi/StrDup.c diff --git a/dll/win32/shlwapi/string.c b/dll/win32/shlwapi/string.c index 6dc9ff8e59d..0285f6cd58a 100644 --- a/dll/win32/shlwapi/string.c +++ b/dll/win32/shlwapi/string.c @@ -1068,6 +1068,10 @@ LPSTR WINAPI StrDupA(LPCSTR lpszStr) TRACE("(%s)\n",debugstr_a(lpszStr)); +#ifdef __REACTOS__ + if (!lpszStr) + return NULL; +#endif iLen = lpszStr ? strlen(lpszStr) + 1 : 1; lpszRet = LocalAlloc(LMEM_FIXED, iLen); @@ -1093,6 +1097,10 @@ LPWSTR WINAPI StrDupW(LPCWSTR lpszStr) TRACE("(%s)\n",debugstr_w(lpszStr)); +#ifdef __REACTOS__ + if (!lpszStr) + return NULL; +#endif iLen = (lpszStr ? strlenW(lpszStr) + 1 : 1) * sizeof(WCHAR); lpszRet = LocalAlloc(LMEM_FIXED, iLen); diff --git a/modules/rostests/apitests/shlwapi/CMakeLists.txt b/modules/rostests/apitests/shlwapi/CMakeLists.txt index 4000fd26775..7a9a57e40aa 100644 --- a/modules/rostests/apitests/shlwapi/CMakeLists.txt +++ b/modules/rostests/apitests/shlwapi/CMakeLists.txt @@ -17,6 +17,7 @@ list(APPEND SOURCE SHLoadIndirectString.c SHLoadRegUIString.c SHPropertyBag.cpp + StrDup.c StrFormatByteSizeW.c testdata.rc testlist.c) diff --git a/modules/rostests/apitests/shlwapi/StrDup.c b/modules/rostests/apitests/shlwapi/StrDup.c new file mode 100644 index 00000000000..4872b77948d --- /dev/null +++ b/modules/rostests/apitests/shlwapi/StrDup.c @@ -0,0 +1,46 @@ +/* + * PROJECT: ReactOS api tests + * LICENSE: GPL-2.0-or-later (https://spdx.org/licenses/GPL-2.0-or-later) + * PURPOSE: Tests for StrDupA/W + * COPYRIGHT: Copyright 2024 Katayama Hirofumi MZ + */ + +#include +#include +#include + +static void TEST_StrDupA(void) +{ + LPSTR ptrA; + + ptrA = StrDupA(NULL); + + if (IsWindowsXPOrGreater()) + ok_ptr(ptrA, NULL); + else + ok(ptrA && !*ptrA, "ptrA: '%s'\n", wine_dbgstr_a(ptrA)); + + if (ptrA) + LocalFree(ptrA); +} + +static void TEST_StrDupW(void) +{ + LPWSTR ptrW; + + ptrW = StrDupW(NULL); + + if (IsWindowsXPOrGreater()) + ok_ptr(ptrW, NULL); + else + ok(ptrW && !*ptrW, "ptrW: '%s'\n", wine_dbgstr_w(ptrW)); + + if (ptrW) + LocalFree(ptrW); +} + +START_TEST(StrDup) +{ + TEST_StrDupA(); + TEST_StrDupW(); +} diff --git a/modules/rostests/apitests/shlwapi/testlist.c b/modules/rostests/apitests/shlwapi/testlist.c index b497fc8836a..9f94155cf15 100644 --- a/modules/rostests/apitests/shlwapi/testlist.c +++ b/modules/rostests/apitests/shlwapi/testlist.c @@ -13,6 +13,7 @@ extern void func_SHGetRestriction(void); extern void func_SHLoadIndirectString(void); extern void func_SHLoadRegUIString(void); extern void func_SHPropertyBag(void); +extern void func_StrDup(void); extern void func_StrFormatByteSizeW(void); const struct test winetest_testlist[] = @@ -29,6 +30,7 @@ const struct test winetest_testlist[] = { "SHLoadIndirectString", func_SHLoadIndirectString }, { "SHLoadRegUIString", func_SHLoadRegUIString }, { "SHPropertyBag", func_SHPropertyBag }, + { "StrDup", func_StrDup }, { "StrFormatByteSizeW", func_StrFormatByteSizeW }, { 0, 0 } };