From b4d81f851740cdb782e6a48ff2f74280a6a97fd5 Mon Sep 17 00:00:00 2001 From: Alexandre Julliard Date: Wed, 25 Feb 2009 15:04:31 +0100 Subject: [PATCH] msi: Fix handling of buffer sizes in MsiEnumPatchesA and avoid a redundant call to MsiEnumPatchesW. --- dlls/msi/registry.c | 29 ++++++++++++----------------- 1 file changed, 12 insertions(+), 17 deletions(-) diff --git a/dlls/msi/registry.c b/dlls/msi/registry.c index 7f9dcb26ad3..73a36eb0fc7 100644 --- a/dlls/msi/registry.c +++ b/dlls/msi/registry.c @@ -1983,7 +1983,7 @@ UINT WINAPI MsiEnumPatchesExW(LPCWSTR szProductCode, LPCWSTR szUserSid, UINT WINAPI MsiEnumPatchesA(LPCSTR szProduct, DWORD iPatchIndex, LPSTR lpPatchBuf, LPSTR lpTransformsBuf, LPDWORD pcchTransformsBuf) { - LPWSTR product, transforms = NULL; + LPWSTR product, transforms; WCHAR patch[GUID_SIZE]; DWORD len; UINT r; @@ -1998,12 +1998,8 @@ UINT WINAPI MsiEnumPatchesA(LPCSTR szProduct, DWORD iPatchIndex, if (!product) return ERROR_OUTOFMEMORY; - len = 0; - r = MsiEnumPatchesW(product, iPatchIndex, patch, patch, &len); - if (r != ERROR_MORE_DATA) - goto done; - - transforms = msi_alloc(len); + len = *pcchTransformsBuf; + transforms = msi_alloc( len * sizeof(WCHAR) ); if (!transforms) { r = ERROR_OUTOFMEMORY; @@ -2011,24 +2007,23 @@ UINT WINAPI MsiEnumPatchesA(LPCSTR szProduct, DWORD iPatchIndex, } r = MsiEnumPatchesW(product, iPatchIndex, patch, transforms, &len); - if (r != ERROR_SUCCESS) + if (r != ERROR_SUCCESS && r != ERROR_MORE_DATA) goto done; WideCharToMultiByte(CP_ACP, 0, patch, -1, lpPatchBuf, GUID_SIZE, NULL, NULL); - WideCharToMultiByte(CP_ACP, 0, transforms, -1, lpTransformsBuf, - *pcchTransformsBuf - 1, NULL, NULL); - - len = lstrlenW(transforms); - if (*pcchTransformsBuf < len + 1) - { + if (!WideCharToMultiByte(CP_ACP, 0, transforms, -1, lpTransformsBuf, + *pcchTransformsBuf, NULL, NULL)) r = ERROR_MORE_DATA; + + if (r == ERROR_MORE_DATA) + { lpTransformsBuf[*pcchTransformsBuf - 1] = '\0'; - *pcchTransformsBuf = len * sizeof(WCHAR); + *pcchTransformsBuf = len * 2; } else - *pcchTransformsBuf = len; + *pcchTransformsBuf = strlen( lpTransformsBuf ); done: msi_free(transforms); @@ -2078,7 +2073,7 @@ UINT WINAPI MsiEnumPatchesW(LPCWSTR szProduct, DWORD iPatchIndex, if (*pcchTransformsBuf <= lstrlenW(transforms)) { r = ERROR_MORE_DATA; - *pcchTransformsBuf = lstrlenW(transforms) * sizeof(WCHAR); + *pcchTransformsBuf = lstrlenW(transforms); } else *pcchTransformsBuf = lstrlenW(transforms);