msi: Fix handling of buffer sizes in MsiEnumPatchesA and avoid a redundant call to MsiEnumPatchesW.
This commit is contained in:
parent
0e8e77cdbd
commit
b4d81f8517
|
@ -1983,7 +1983,7 @@ UINT WINAPI MsiEnumPatchesExW(LPCWSTR szProductCode, LPCWSTR szUserSid,
|
||||||
UINT WINAPI MsiEnumPatchesA(LPCSTR szProduct, DWORD iPatchIndex,
|
UINT WINAPI MsiEnumPatchesA(LPCSTR szProduct, DWORD iPatchIndex,
|
||||||
LPSTR lpPatchBuf, LPSTR lpTransformsBuf, LPDWORD pcchTransformsBuf)
|
LPSTR lpPatchBuf, LPSTR lpTransformsBuf, LPDWORD pcchTransformsBuf)
|
||||||
{
|
{
|
||||||
LPWSTR product, transforms = NULL;
|
LPWSTR product, transforms;
|
||||||
WCHAR patch[GUID_SIZE];
|
WCHAR patch[GUID_SIZE];
|
||||||
DWORD len;
|
DWORD len;
|
||||||
UINT r;
|
UINT r;
|
||||||
|
@ -1998,12 +1998,8 @@ UINT WINAPI MsiEnumPatchesA(LPCSTR szProduct, DWORD iPatchIndex,
|
||||||
if (!product)
|
if (!product)
|
||||||
return ERROR_OUTOFMEMORY;
|
return ERROR_OUTOFMEMORY;
|
||||||
|
|
||||||
len = 0;
|
len = *pcchTransformsBuf;
|
||||||
r = MsiEnumPatchesW(product, iPatchIndex, patch, patch, &len);
|
transforms = msi_alloc( len * sizeof(WCHAR) );
|
||||||
if (r != ERROR_MORE_DATA)
|
|
||||||
goto done;
|
|
||||||
|
|
||||||
transforms = msi_alloc(len);
|
|
||||||
if (!transforms)
|
if (!transforms)
|
||||||
{
|
{
|
||||||
r = ERROR_OUTOFMEMORY;
|
r = ERROR_OUTOFMEMORY;
|
||||||
|
@ -2011,24 +2007,23 @@ UINT WINAPI MsiEnumPatchesA(LPCSTR szProduct, DWORD iPatchIndex,
|
||||||
}
|
}
|
||||||
|
|
||||||
r = MsiEnumPatchesW(product, iPatchIndex, patch, transforms, &len);
|
r = MsiEnumPatchesW(product, iPatchIndex, patch, transforms, &len);
|
||||||
if (r != ERROR_SUCCESS)
|
if (r != ERROR_SUCCESS && r != ERROR_MORE_DATA)
|
||||||
goto done;
|
goto done;
|
||||||
|
|
||||||
WideCharToMultiByte(CP_ACP, 0, patch, -1, lpPatchBuf,
|
WideCharToMultiByte(CP_ACP, 0, patch, -1, lpPatchBuf,
|
||||||
GUID_SIZE, NULL, NULL);
|
GUID_SIZE, NULL, NULL);
|
||||||
|
|
||||||
WideCharToMultiByte(CP_ACP, 0, transforms, -1, lpTransformsBuf,
|
if (!WideCharToMultiByte(CP_ACP, 0, transforms, -1, lpTransformsBuf,
|
||||||
*pcchTransformsBuf - 1, NULL, NULL);
|
*pcchTransformsBuf, NULL, NULL))
|
||||||
|
|
||||||
len = lstrlenW(transforms);
|
|
||||||
if (*pcchTransformsBuf < len + 1)
|
|
||||||
{
|
|
||||||
r = ERROR_MORE_DATA;
|
r = ERROR_MORE_DATA;
|
||||||
|
|
||||||
|
if (r == ERROR_MORE_DATA)
|
||||||
|
{
|
||||||
lpTransformsBuf[*pcchTransformsBuf - 1] = '\0';
|
lpTransformsBuf[*pcchTransformsBuf - 1] = '\0';
|
||||||
*pcchTransformsBuf = len * sizeof(WCHAR);
|
*pcchTransformsBuf = len * 2;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
*pcchTransformsBuf = len;
|
*pcchTransformsBuf = strlen( lpTransformsBuf );
|
||||||
|
|
||||||
done:
|
done:
|
||||||
msi_free(transforms);
|
msi_free(transforms);
|
||||||
|
@ -2078,7 +2073,7 @@ UINT WINAPI MsiEnumPatchesW(LPCWSTR szProduct, DWORD iPatchIndex,
|
||||||
if (*pcchTransformsBuf <= lstrlenW(transforms))
|
if (*pcchTransformsBuf <= lstrlenW(transforms))
|
||||||
{
|
{
|
||||||
r = ERROR_MORE_DATA;
|
r = ERROR_MORE_DATA;
|
||||||
*pcchTransformsBuf = lstrlenW(transforms) * sizeof(WCHAR);
|
*pcchTransformsBuf = lstrlenW(transforms);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
*pcchTransformsBuf = lstrlenW(transforms);
|
*pcchTransformsBuf = lstrlenW(transforms);
|
||||||
|
|
Loading…
Reference in New Issue