comctl32/mru: In EnumMRUListA, ensure that the string is NULL terminated and the correct size is returned.

This commit is contained in:
Reece Dunn 2010-02-26 07:20:12 +00:00 committed by Alexandre Julliard
parent 3fbe40e2f9
commit 78ce24d632
2 changed files with 8 additions and 6 deletions

View File

@ -885,9 +885,11 @@ INT WINAPI EnumMRUListA (HANDLE hList, INT nItemPos, LPVOID lpBuffer,
} else { } else {
lenA = WideCharToMultiByte(CP_ACP, 0, (LPWSTR)&witem->datastart, -1, lenA = WideCharToMultiByte(CP_ACP, 0, (LPWSTR)&witem->datastart, -1,
NULL, 0, NULL, NULL); NULL, 0, NULL, NULL);
datasize = min( witem->size, nBufferSize ); datasize = min( lenA, nBufferSize );
WideCharToMultiByte(CP_ACP, 0, (LPWSTR)&witem->datastart, -1, WideCharToMultiByte(CP_ACP, 0, (LPWSTR)&witem->datastart, -1,
lpBuffer, datasize, NULL, NULL); lpBuffer, datasize, NULL, NULL);
((char *)lpBuffer)[ datasize - 1 ] = '\0';
datasize = lenA - 1;
} }
TRACE("(%p, %d, %p, %d): returning len=%d\n", TRACE("(%p, %d, %p, %d): returning len=%d\n",
hList, nItemPos, lpBuffer, nBufferSize, datasize); hList, nItemPos, lpBuffer, nBufferSize, datasize);

View File

@ -385,7 +385,7 @@ static void test_MRUListA(void)
/* check entry 0 */ /* check entry 0 */
buffer[0] = 0; buffer[0] = 0;
iRet = pEnumMRUList(hMRU, 0, buffer, 255); 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); ok(strcmp(buffer, checks[3]) == 0, "EnumMRUList expected %s, got %s\n", checks[3], buffer);
/* check entry 0 with a too small buffer */ /* check entry 0 with a too small buffer */
@ -394,21 +394,21 @@ static void test_MRUListA(void)
buffer[2] = 'A'; /* unchanged */ buffer[2] = 'A'; /* unchanged */
buffer[3] = 0; /* unchanged */ buffer[3] = 0; /* unchanged */
iRet = pEnumMRUList(hMRU, 0, buffer, 2); iRet = pEnumMRUList(hMRU, 0, buffer, 2);
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);
todo_wine ok(strcmp(buffer, "T") == 0, "EnumMRUList expected %s, got %s\n", "T", buffer); ok(strcmp(buffer, "T") == 0, "EnumMRUList expected %s, got %s\n", "T", buffer);
/* make sure space after buffer has old values */ /* make sure space after buffer has old values */
ok(buffer[2] == 'A', "EnumMRUList expected %02x, got %02x\n", 'A', buffer[2]); ok(buffer[2] == 'A', "EnumMRUList expected %02x, got %02x\n", 'A', buffer[2]);
/* check entry 1 */ /* check entry 1 */
buffer[0] = 0; buffer[0] = 0;
iRet = pEnumMRUList(hMRU, 1, buffer, 255); 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); ok(strcmp(buffer, checks[1]) == 0, "EnumMRUList expected %s, got %s\n", checks[1], buffer);
/* check entry 2 */ /* check entry 2 */
buffer[0] = 0; buffer[0] = 0;
iRet = pEnumMRUList(hMRU, 2, buffer, 255); 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); ok(strcmp(buffer, checks[2]) == 0, "EnumMRUList expected %s, got %s\n", checks[2], buffer);
/* check out of bounds entry 3 */ /* check out of bounds entry 3 */