From a8a2cb2eb23b299eb91297d9107ad101fe0a0104 Mon Sep 17 00:00:00 2001 From: Daniel Lehman Date: Mon, 13 Aug 2018 17:42:06 -0700 Subject: [PATCH v2 4/4] msvcrt: Don't read past end of string in _strnicoll/_wcsnicoll. Signed-off-by: Daniel Lehman --- dlls/msvcrt/string.c | 2 +- dlls/msvcrt/tests/string.c | 33 +++++++++++++-------------------- dlls/msvcrt/wcs.c | 2 +- 3 files changed, 15 insertions(+), 22 deletions(-) diff --git a/dlls/msvcrt/string.c b/dlls/msvcrt/string.c index 90d359181d..cd4b844d6a 100644 --- a/dlls/msvcrt/string.c +++ b/dlls/msvcrt/string.c @@ -693,7 +693,7 @@ int CDECL MSVCRT__strnicoll_l( const char* str1, const char* str2, MSVCRT_size_t if(!locinfo->lc_handle[MSVCRT_LC_COLLATE]) return strncasecmp(str1, str2, count); return CompareStringA(locinfo->lc_handle[MSVCRT_LC_COLLATE], NORM_IGNORECASE, - str1, count, str2, count)-CSTR_EQUAL; + str1, strnlen(str1, count), str2, strnlen(str2, count))-CSTR_EQUAL; } /********************************************************************* diff --git a/dlls/msvcrt/tests/string.c b/dlls/msvcrt/tests/string.c index f642549937..d70ba849ba 100644 --- a/dlls/msvcrt/tests/string.c +++ b/dlls/msvcrt/tests/string.c @@ -3478,11 +3478,10 @@ static void test__tcsnicoll(void) const char *str2; size_t count; int exp; - BOOL todo; }; static const struct test tests[] = { { "English", "abcd", "ABCD", 4, 0 }, - { "English", "abcd", "ABCD", 10, 0, TRUE }, + { "English", "abcd", "ABCD", 10, 0 }, { "English", "abc", "ABCD", 3, 0 }, { "English", "abc", "ABCD", 4, -1 }, @@ -3527,15 +3526,12 @@ static void test__tcsnicoll(void) strcpy(str2, tests[i].str2); ret = _strnicoll(str1, str2, tests[i].count); - todo_wine_if(tests[i].todo) - { - if (!tests[i].exp) - ok(!ret, "expected 0, got %d for %s, %s, %d\n", ret, str1, str2, (int)tests[i].count); - else if (tests[i].exp < 0) - ok(ret < 0, "expected < 0, got %d for %s, %s, %d\n", ret, str1, str2, (int)tests[i].count); - else - ok(ret > 0, "expected > 0, got %d for %s, %s, %d\n", ret, str1, str2, (int)tests[i].count); - } + if (!tests[i].exp) + ok(!ret, "expected 0, got %d for %s, %s, %d\n", ret, str1, str2, (int)tests[i].count); + else if (tests[i].exp < 0) + ok(ret < 0, "expected < 0, got %d for %s, %s, %d\n", ret, str1, str2, (int)tests[i].count); + else + ok(ret > 0, "expected > 0, got %d for %s, %s, %d\n", ret, str1, str2, (int)tests[i].count); memset(str1W, 0xee, sizeof(str1W)); len = mbstowcs(str1W, str1, ARRAY_SIZE(str1W)); @@ -3546,15 +3542,12 @@ static void test__tcsnicoll(void) str2W[len] = 0; ret = _wcsnicoll(str1W, str2W, tests[i].count); - todo_wine_if(tests[i].todo) - { - if (!tests[i].exp) - ok(!ret, "expected 0, got %d for %s, %s, %d\n", ret, str1, str2, (int)tests[i].count); - else if (tests[i].exp < 0) - ok(ret < 0, "expected < 0, got %d for %s, %s, %d\n", ret, str1, str2, (int)tests[i].count); - else - ok(ret > 0, "expected > 0, got %d for %s, %s, %d\n", ret, str1, str2, (int)tests[i].count); - } + if (!tests[i].exp) + ok(!ret, "expected 0, got %d for %s, %s, %d\n", ret, str1, str2, (int)tests[i].count); + else if (tests[i].exp < 0) + ok(ret < 0, "expected < 0, got %d for %s, %s, %d\n", ret, str1, str2, (int)tests[i].count); + else + ok(ret > 0, "expected > 0, got %d for %s, %s, %d\n", ret, str1, str2, (int)tests[i].count); } } diff --git a/dlls/msvcrt/wcs.c b/dlls/msvcrt/wcs.c index 6fca17ed47..554322daa3 100644 --- a/dlls/msvcrt/wcs.c +++ b/dlls/msvcrt/wcs.c @@ -151,7 +151,7 @@ int CDECL MSVCRT__wcsnicoll_l(const MSVCRT_wchar_t* str1, const MSVCRT_wchar_t* if(!locinfo->lc_handle[MSVCRT_LC_COLLATE]) return strncmpiW(str1, str2, count); return CompareStringW(locinfo->lc_handle[MSVCRT_LC_COLLATE], NORM_IGNORECASE, - str1, count, str2, count)-CSTR_EQUAL; + str1, strnlenW(str1, count), str2, strnlenW(str2, count))-CSTR_EQUAL; } /********************************************************************* -- 2.17.0