From: Bartosz Kosiorek gang65@poczta.onet.pl
--- dlls/msvcrt/string.c | 20 +++++++++++++++++--- dlls/ucrtbase/tests/string.c | 24 +++++++++++++++++++++--- 2 files changed, 38 insertions(+), 6 deletions(-)
diff --git a/dlls/msvcrt/string.c b/dlls/msvcrt/string.c index d58a21406b1..82c05018b87 100644 --- a/dlls/msvcrt/string.c +++ b/dlls/msvcrt/string.c @@ -3313,11 +3313,15 @@ int __cdecl _strnicmp_l(const char *s1, const char *s2, pthreadlocinfo locinfo; int c1, c2;
- if(s1==NULL || s2==NULL) - return _NLSCMPERROR; - if(!count) return 0; +#if _MSVCR_VER>=140 + if(!MSVCRT_CHECK_PMT(s1 && s2 && count <= INT_MAX)) +#else + /* Old versions of msvcrt.dll didn't have count <= INT_MAX check */ + if(!MSVCRT_CHECK_PMT(s1 && s2)) +#endif /* _MSVCR_VER>=140 */ + return _NLSCMPERROR;
if(!locale) locinfo = get_locinfo(); @@ -3349,7 +3353,12 @@ int __cdecl _strnicmp_l(const char *s1, const char *s2, */ int __cdecl _stricmp_l(const char *s1, const char *s2, _locale_t locale) { +#if _MSVCR_VER>=140 + return _strnicmp_l(s1, s2, INT_MAX, locale); +#else + /* Old versions of msvcrt.dll didn't have count <= INT_MAX check */ return _strnicmp_l(s1, s2, -1, locale); +#endif /* _MSVCR_VER>=140 */ }
/********************************************************************* @@ -3365,7 +3374,12 @@ int __cdecl _strnicmp(const char *s1, const char *s2, size_t count) */ int __cdecl _stricmp(const char *s1, const char *s2) { +#if _MSVCR_VER>=140 + return _strnicmp_l(s1, s2, INT_MAX, NULL); +#else + /* Old versions of msvcrt.dll didn't have count <= INT_MAX check */ return _strnicmp_l(s1, s2, -1, NULL); +#endif /* _MSVCR_VER>=140 */ }
/********************************************************************* diff --git a/dlls/ucrtbase/tests/string.c b/dlls/ucrtbase/tests/string.c index 2c6a02da7ae..6dcd15fb5b9 100644 --- a/dlls/ucrtbase/tests/string.c +++ b/dlls/ucrtbase/tests/string.c @@ -480,15 +480,33 @@ static void test__strnicmp(void) static const char str2[] = "test"; int ret;
+ SET_EXPECT(invalid_parameter_handler); + errno = 0xdeadbeef; + ret = _strnicmp(str1, NULL, 2); + CHECK_CALLED(invalid_parameter_handler); + ok(ret == _NLSCMPERROR, "got %d.\n", ret); + ok(errno == EINVAL, "Unexpected errno %d.\n", errno); + SET_EXPECT(invalid_parameter_handler); errno = 0xdeadbeef; ret = _strnicmp(str1, str2, -1); - todo_wine CHECK_CALLED(invalid_parameter_handler); - todo_wine ok(ret == _NLSCMPERROR, "got %d.\n", ret); - todo_wine ok(errno == EINVAL, "Unexpected errno %d.\n", errno); + CHECK_CALLED(invalid_parameter_handler); + ok(ret == _NLSCMPERROR, "got %d.\n", ret); + ok(errno == EINVAL, "Unexpected errno %d.\n", errno); + + ret = _strnicmp(str1, str2, 0); + ok(!ret, "got %d.\n", ret);
ret = _strnicmp(str1, str2, 0x7fffffff); ok(!ret, "got %d.\n", ret); + + /* If numbers of characters to compare is too big return error */ + SET_EXPECT(invalid_parameter_handler); + errno = 0xdeadbeef; + ret = _strnicmp(str1, str2, 0x80000000); + CHECK_CALLED(invalid_parameter_handler); + ok(ret == _NLSCMPERROR, "got %d.\n", ret); + ok(errno == EINVAL, "Unexpected errno %d.\n", errno); }
static void test_wcsnicmp(void)