From: Hans Leidekker Subject: [3/4] msi: Return an error from MSI_GetComponentPath if the buffer is too small. Message-Id: <1409580259.23218.24.camel@t400> Date: Mon, 01 Sep 2014 16:04:19 +0200 --- dlls/msi/msi.c | 14 ++++++++++---- dlls/msi/tests/msi.c | 14 ++++++++++++++ 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/dlls/msi/msi.c b/dlls/msi/msi.c index 5b344ca..70a8134 100644 --- a/dlls/msi/msi.c +++ b/dlls/msi/msi.c @@ -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; diff --git a/dlls/msi/tests/msi.c b/dlls/msi/tests/msi.c index 3897c24..c517fcf 100644 --- a/dlls/msi/tests/msi.c +++ b/dlls/msi/tests/msi.c @@ -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); -- 2.1.0