Commit cdd135c2 authored by Rob Shearman's avatar Rob Shearman Committed by Alexandre Julliard

wininet: Fix URLCache_LocalFileNameToPathA to return a full path, rather than…

wininet: Fix URLCache_LocalFileNameToPathA to return a full path, rather than just the container path. This was caused by path_len including the nul-terminator and so the rest of the string was being added after the nul-terminator, which is incorrect. This is fixed by making path_len not include the nul-terminator. Also fix a few other issues with the function, like not passing a correct length into the second call to WideCharToMultiByte, nRequired being calculated incorrectly and the string not always being nul-terminated. Add a test for this function by testing the lpszLocalFileName field obtained from RetrieveUrlCacheEntryFileA.
parent c46279ce
......@@ -70,6 +70,7 @@ static void test_urlcacheA(void)
ok(lpCacheEntryInfo->dwStructSize == sizeof(*lpCacheEntryInfo), "lpCacheEntryInfo->dwStructSize was %d\n", lpCacheEntryInfo->dwStructSize);
ok(!strcmp(lpCacheEntryInfo->lpszSourceUrlName, TEST_URL), "lpCacheEntryInfo->lpszSourceUrlName should be %s instead of %s\n", TEST_URL, lpCacheEntryInfo->lpszSourceUrlName);
ok(!strcmp(lpCacheEntryInfo->lpszLocalFileName, filename), "lpCacheEntryInfo->lpszLocalFileName should be %s instead of %s\n", filename, lpCacheEntryInfo->lpszLocalFileName);
HeapFree(GetProcessHeap(), 0, lpCacheEntryInfo);
......
......@@ -909,14 +909,14 @@ static BOOL URLCache_LocalFileNameToPathA(
return FALSE;
}
path_len = WideCharToMultiByte(CP_ACP, 0, pContainer->path, -1, NULL, 0, NULL, NULL);
file_name_len = strlen(szLocalFileName);
path_len = WideCharToMultiByte(CP_ACP, 0, pContainer->path, -1, NULL, 0, NULL, NULL) - 1;
file_name_len = strlen(szLocalFileName) + 1 /* for nul-terminator */;
dir_len = DIR_LENGTH;
nRequired = (path_len + dir_len + 1 + file_name_len) * sizeof(WCHAR);
nRequired = (path_len + dir_len + 1 + file_name_len) * sizeof(char);
if (nRequired < *lpBufferSize)
{
WideCharToMultiByte(CP_ACP, 0, pContainer->path, -1, szPath, -1, NULL, NULL);
WideCharToMultiByte(CP_ACP, 0, pContainer->path, -1, szPath, path_len, NULL, NULL);
memcpy(szPath+path_len, pHeader->directory_data[Directory].filename, dir_len);
szPath[path_len + dir_len] = '\\';
memcpy(szPath + path_len + dir_len + 1, szLocalFileName, file_name_len);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment