diff --git a/dlls/setupapi/query.c b/dlls/setupapi/query.c index fd56f96f891..3e680eb03ba 100644 --- a/dlls/setupapi/query.c +++ b/dlls/setupapi/query.c @@ -130,6 +130,7 @@ BOOL WINAPI SetupGetInfInformationW(LPCVOID InfSpec, DWORD SearchControl, { HINF inf; BOOL ret; + DWORD infSize; TRACE("(%p, %ld, %p, %ld, %p)\n", InfSpec, SearchControl, ReturnBuffer, ReturnBufferSize, RequiredSize); @@ -144,12 +145,6 @@ BOOL WINAPI SetupGetInfInformationW(LPCVOID InfSpec, DWORD SearchControl, return FALSE; } - if (!ReturnBuffer && ReturnBufferSize) - { - SetLastError(ERROR_INVALID_PARAMETER); - return FALSE; - } - switch (SearchControl) { case INFINFO_INF_SPEC_IS_HINF: @@ -181,7 +176,13 @@ BOOL WINAPI SetupGetInfInformationW(LPCVOID InfSpec, DWORD SearchControl, return FALSE; } - ret = fill_inf_info(inf, ReturnBuffer, ReturnBufferSize, RequiredSize); + ret = fill_inf_info(inf, ReturnBuffer, ReturnBufferSize, &infSize); + if (!ReturnBuffer && (ReturnBufferSize >= infSize)) + { + SetLastError(ERROR_INVALID_PARAMETER); + ret = FALSE; + } + if (RequiredSize) *RequiredSize = infSize; if (SearchControl >= INFINFO_INF_NAME_IS_ABSOLUTE) SetupCloseInfFile(inf); diff --git a/dlls/setupapi/tests/query.c b/dlls/setupapi/tests/query.c index e823e7d2473..0ac23da60c1 100644 --- a/dlls/setupapi/tests/query.c +++ b/dlls/setupapi/tests/query.c @@ -177,13 +177,25 @@ static void test_SetupGetInfInformation(void) ok(ret == TRUE, "Expected SetupGetInfInformation to succeed\n"); ok(size != 0xdeadbeef, "Expected a valid size on return\n"); - /* set ReturnBuffer to NULL and ReturnBufferSize to non-zero */ + /* set ReturnBuffer to NULL and ReturnBufferSize to non-zero value 'size' */ SetLastError(0xbeefcafe); ret = pSetupGetInfInformationA(inf_filename, INFINFO_INF_NAME_IS_ABSOLUTE, NULL, size, &size); ok(ret == FALSE, "Expected SetupGetInfInformation to fail\n"); ok(GetLastError() == ERROR_INVALID_PARAMETER, "Expected ERROR_INVALID_PARAMETER, got %ld\n", GetLastError()); + /* set ReturnBuffer to NULL and ReturnBufferSize to non-zero value 'size-1' */ + ret = pSetupGetInfInformationA(inf_filename, INFINFO_INF_NAME_IS_ABSOLUTE, NULL, size-1, &size); + ok(ret == TRUE, "Expected SetupGetInfInformation to succeed\n"); + + /* some tests for behaviour with a NULL RequiredSize pointer */ + ret = pSetupGetInfInformationA(inf_filename, INFINFO_INF_NAME_IS_ABSOLUTE, NULL, 0, NULL); + ok(ret == TRUE, "Expected SetupGetInfInformation to succeed\n"); + ret = pSetupGetInfInformationA(inf_filename, INFINFO_INF_NAME_IS_ABSOLUTE, NULL, size - 1, NULL); + ok(ret == TRUE, "Expected SetupGetInfInformation to succeed\n"); + ret = pSetupGetInfInformationA(inf_filename, INFINFO_INF_NAME_IS_ABSOLUTE, NULL, size, NULL); + ok(ret == FALSE, "Expected SetupGetInfInformation to fail\n"); + info = HeapAlloc(GetProcessHeap(), 0, size); /* try valid ReturnBuffer but too small size */