msi: Return an error from MSI_GetComponentPath if the buffer is too small.

This commit is contained in:
Hans Leidekker 2014-09-01 16:04:19 +02:00 committed by Alexandre Julliard
parent 04f9058a28
commit 5709249986
2 changed files with 24 additions and 4 deletions

View File

@ -2865,7 +2865,9 @@ static INSTALLSTATE MSI_GetComponentPath(LPCWSTR szProduct, LPCWSTR szComponent,
if (state == INSTALLSTATE_LOCAL && !*path)
state = INSTALLSTATE_NOTUSED;
msi_strcpy_to_awstring(path, -1, lpPathBuf, pcchBuf);
if (msi_strcpy_to_awstring(path, -1, lpPathBuf, pcchBuf) == ERROR_MORE_DATA)
state = INSTALLSTATE_MOREDATA;
msi_free(path);
return state;
}
@ -3379,6 +3381,7 @@ static UINT MSI_ProvideQualifiedComponentEx(LPCWSTR szComponent,
HKEY hkey;
DWORD sz;
UINT rc;
INSTALLSTATE state;
rc = MSIREG_OpenUserComponentsKey(szComponent, &hkey, FALSE);
if (rc != ERROR_SUCCESS)
@ -3393,13 +3396,16 @@ static UINT MSI_ProvideQualifiedComponentEx(LPCWSTR szComponent,
MsiDecomposeDescriptorW(info, product, feature, component, &sz);
if (!szProduct)
rc = MSI_GetComponentPath(product, component, lpPathBuf, pcchPathBuf);
state = MSI_GetComponentPath(product, component, lpPathBuf, pcchPathBuf);
else
rc = MSI_GetComponentPath(szProduct, component, lpPathBuf, pcchPathBuf);
state = MSI_GetComponentPath(szProduct, component, lpPathBuf, pcchPathBuf);
msi_free( info );
if (rc != INSTALLSTATE_LOCAL)
if (state == INSTALLSTATE_MOREDATA)
return ERROR_MORE_DATA;
if (state != INSTALLSTATE_LOCAL)
return ERROR_FILE_NOT_FOUND;
return ERROR_SUCCESS;

View File

@ -3008,6 +3008,13 @@ static void test_MsiGetComponentPath(void)
create_file("C:\\imapath", "C:\\imapath", 11);
/* file exists */
path[0] = 'a';
size = 0;
state = MsiGetComponentPathA(prodcode, component, path, &size);
ok(state == INSTALLSTATE_MOREDATA, "Expected INSTALLSTATE_MOREDATA, got %d\n", state);
ok(path[0] == 'a', "got %s\n", path);
ok(size == 10, "Expected 10, got %d\n", size);
path[0] = 0;
size = MAX_PATH;
state = MsiGetComponentPathA(prodcode, component, path, &size);
@ -3015,6 +3022,13 @@ static void test_MsiGetComponentPath(void)
ok(!lstrcmpA(path, "C:\\imapath"), "Expected C:\\imapath, got %s\n", path);
ok(size == 10, "Expected 10, got %d\n", size);
size = 0;
path[0] = 'a';
state = MsiLocateComponentA(component, path, &size);
ok(state == INSTALLSTATE_MOREDATA, "Expected INSTALLSTATE_MOREDATA, got %d\n", state);
ok(path[0] == 'a', "got %s\n", path);
ok(size == 10, "Expected 10, got %d\n", size);
path[0] = 0;
size = MAX_PATH;
state = MsiLocateComponentA(component, path, &size);