[WINSPOOL] Properly copy the DEVMODE in IntFixUpDevModeNames

Otherwise the size isn't set up correctly, leading to a crash.
Fixes crash in comdl32_winetest printdlg.
This commit is contained in:
Timo Kreuzer 2023-09-19 16:33:35 +03:00
parent 8c76870639
commit 02df49ebd8

View file

@ -834,7 +834,19 @@ IntFixUpDevModeNames( PDOCUMENTPROPERTYHEADER pdphdr )
if (res)
{
FIXME("IFUDMN : Get Printer Name %S\n",pi2->pPrinterName);
/* Check if the provided buffer is large enough */
DWORD cbDevMode = pi2->pDevMode->dmSize + pi2->pDevMode->dmDriverExtra;
if (pdphdr->cbOut < cbDevMode)
{
ERR("cbOut (%lu) < cbDevMode(%u)\n", pdphdr->cbOut, cbDevMode);
res = FALSE;
goto Exit;
}
/* Copy the devmode */
RtlCopyMemory(pdphdr->pdmOut, pi2->pDevMode, cbDevMode);
TRACE("IFUDMN : Get Printer Name %S\n", pi2->pPrinterName);
StringCchCopyW( pdphdr->pdmOut->dmDeviceName, CCHDEVICENAME-1, pi2->pPrinterName );
pdphdr->pdmOut->dmDeviceName[CCHDEVICENAME-1] = 0;
}
@ -842,6 +854,8 @@ IntFixUpDevModeNames( PDOCUMENTPROPERTYHEADER pdphdr )
{
ERR("IFUDMN : GetPrinterW failed with %u\n", GetLastError());
}
Exit:
HeapFree(hProcessHeap, 0, pi2);
return res;
}