diff --git a/dlls/msi/source.c b/dlls/msi/source.c index 53a2821c662..e44b3a17e91 100644 --- a/dlls/msi/source.c +++ b/dlls/msi/source.c @@ -189,12 +189,13 @@ UINT WINAPI MsiSourceListEnumSourcesA(LPCSTR szProductCodeOrPatch, LPCSTR szUser goto done; len = WideCharToMultiByte(CP_ACP, 0, source, -1, NULL, 0, NULL, NULL); - if (*pcchSource >= len) + if (pcchSource && *pcchSource >= len) WideCharToMultiByte(CP_ACP, 0, source, -1, szSource, len, NULL, NULL); else if (szSource) r = ERROR_MORE_DATA; - *pcchSource = len - 1; + if (pcchSource) + *pcchSource = len - 1; done: msi_free(product); @@ -203,7 +204,7 @@ done: if (r == ERROR_SUCCESS) { - if (szSource) index++; + if (szSource || !pcchSource) index++; } else if (dwIndex > index) index = 0; @@ -281,7 +282,7 @@ done: if (r == ERROR_SUCCESS) { - if (szSource) index++; + if (szSource || !pcchSource) index++; } else if (dwIndex > index) index = 0; diff --git a/dlls/msi/tests/source.c b/dlls/msi/tests/source.c index e76a277bdaa..8a275d27585 100644 --- a/dlls/msi/tests/source.c +++ b/dlls/msi/tests/source.c @@ -883,6 +883,18 @@ static void test_MsiSourceListEnumSources(void) ok(!lstrcmpA(value, "first"), "Expected \"first\", got %s\n", value); ok(size == 5, "Expected 5, got %d\n", size); + /* both szSource and pcchSource are NULL, index 0 */ + r = MsiSourceListEnumSourcesA(prodcode, usersid, + MSIINSTALLCONTEXT_USERUNMANAGED, + MSICODE_PRODUCT | MSISOURCETYPE_URL, 0, NULL, NULL); + ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r); + + /* both szSource and pcchSource are NULL, index 1 */ + r = MsiSourceListEnumSourcesA(prodcode, usersid, + MSIINSTALLCONTEXT_USERUNMANAGED, + MSICODE_PRODUCT | MSISOURCETYPE_URL, 1, NULL, NULL); + ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r); + /* size is exactly 5 */ size = 5; lstrcpyA(value, "aaa");