Windows: Fix potential crash when retrieving default printer

GetDefaultPrinter() has been observed to return size == 0.

Pick-to: 6.3 6.2 5.15
Fixes: QTBUG-53290
Change-Id: Id4c7a06d14d368c792e15e55cacf2366b6aedc7b
Reviewed-by: Andy Shaw <andy.shaw@qt.io>
This commit is contained in:
Friedemann Kleint 2022-03-25 18:03:19 +01:00
parent d85c6527b5
commit 0cdb44f01f

View File

@ -499,7 +499,7 @@ QStringList QWindowsPrintDevice::availablePrintDeviceIds()
QString QWindowsPrintDevice::defaultPrintDeviceId()
{
DWORD size = 0;
if (GetDefaultPrinter(nullptr, &size) == ERROR_FILE_NOT_FOUND)
if (GetDefaultPrinter(nullptr, &size) == ERROR_FILE_NOT_FOUND || size < 2)
return QString();
QScopedArrayPointer<wchar_t> name(new wchar_t[size]);