From 78ce24d632c497aa4162952323c411cfddfc5207 Mon Sep 17 00:00:00 2001 From: Reece Dunn Date: Fri, 26 Feb 2010 07:20:12 +0000 Subject: [PATCH] comctl32/mru: In EnumMRUListA, ensure that the string is NULL terminated and the correct size is returned. --- dlls/comctl32/comctl32undoc.c | 4 +++- dlls/comctl32/tests/mru.c | 10 +++++----- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/dlls/comctl32/comctl32undoc.c b/dlls/comctl32/comctl32undoc.c index ee684c627d..ff94051bcc 100644 --- a/dlls/comctl32/comctl32undoc.c +++ b/dlls/comctl32/comctl32undoc.c @@ -885,9 +885,11 @@ INT WINAPI EnumMRUListA (HANDLE hList, INT nItemPos, LPVOID lpBuffer, } else { lenA = WideCharToMultiByte(CP_ACP, 0, (LPWSTR)&witem->datastart, -1, NULL, 0, NULL, NULL); - datasize = min( witem->size, nBufferSize ); + datasize = min( lenA, nBufferSize ); WideCharToMultiByte(CP_ACP, 0, (LPWSTR)&witem->datastart, -1, lpBuffer, datasize, NULL, NULL); + ((char *)lpBuffer)[ datasize - 1 ] = '\0'; + datasize = lenA - 1; } TRACE("(%p, %d, %p, %d): returning len=%d\n", hList, nItemPos, lpBuffer, nBufferSize, datasize); diff --git a/dlls/comctl32/tests/mru.c b/dlls/comctl32/tests/mru.c index c4da87b1dd..3eae9a9db9 100644 --- a/dlls/comctl32/tests/mru.c +++ b/dlls/comctl32/tests/mru.c @@ -385,7 +385,7 @@ static void test_MRUListA(void) /* check entry 0 */ buffer[0] = 0; iRet = pEnumMRUList(hMRU, 0, buffer, 255); - todo_wine ok(iRet == lstrlen(checks[3]), "EnumMRUList expected %d, got %d\n", lstrlen(checks[3]), iRet); + ok(iRet == lstrlen(checks[3]), "EnumMRUList expected %d, got %d\n", lstrlen(checks[3]), iRet); ok(strcmp(buffer, checks[3]) == 0, "EnumMRUList expected %s, got %s\n", checks[3], buffer); /* check entry 0 with a too small buffer */ @@ -394,21 +394,21 @@ static void test_MRUListA(void) buffer[2] = 'A'; /* unchanged */ buffer[3] = 0; /* unchanged */ iRet = pEnumMRUList(hMRU, 0, buffer, 2); - todo_wine ok(iRet == lstrlen(checks[3]), "EnumMRUList expected %d, got %d\n", lstrlen(checks[3]), iRet); - todo_wine ok(strcmp(buffer, "T") == 0, "EnumMRUList expected %s, got %s\n", "T", buffer); + ok(iRet == lstrlen(checks[3]), "EnumMRUList expected %d, got %d\n", lstrlen(checks[3]), iRet); + ok(strcmp(buffer, "T") == 0, "EnumMRUList expected %s, got %s\n", "T", buffer); /* make sure space after buffer has old values */ ok(buffer[2] == 'A', "EnumMRUList expected %02x, got %02x\n", 'A', buffer[2]); /* check entry 1 */ buffer[0] = 0; iRet = pEnumMRUList(hMRU, 1, buffer, 255); - todo_wine ok(iRet == lstrlen(checks[1]), "EnumMRUList expected %d, got %d\n", lstrlen(checks[1]), iRet); + ok(iRet == lstrlen(checks[1]), "EnumMRUList expected %d, got %d\n", lstrlen(checks[1]), iRet); ok(strcmp(buffer, checks[1]) == 0, "EnumMRUList expected %s, got %s\n", checks[1], buffer); /* check entry 2 */ buffer[0] = 0; iRet = pEnumMRUList(hMRU, 2, buffer, 255); - todo_wine ok(iRet == lstrlen(checks[2]), "EnumMRUList expected %d, got %d\n", lstrlen(checks[2]), iRet); + ok(iRet == lstrlen(checks[2]), "EnumMRUList expected %d, got %d\n", lstrlen(checks[2]), iRet); ok(strcmp(buffer, checks[2]) == 0, "EnumMRUList expected %s, got %s\n", checks[2], buffer); /* check out of bounds entry 3 */