Work around buggy printer drivers not returning correct DEVMODE size.

Apparently at least one printer driver doesn't report the memory needed by its
own DEVMODE struct correctly, resulting in a crash due to a buffer overflow
when printing using it.

Work around this by allocating slightly more memory than what we really need.

Closes #16274.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@77654 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin 2014-09-10 16:51:21 +00:00
parent 9a377ec117
commit 9dbf785a99

View File

@ -413,6 +413,13 @@ void wxWindowsPrintNativeData::InitializeDevMode(const wxString& printerName, Wi
NULL, // these are not used.
0 ); // Zero returns buffer size.
// Some buggy printer drivers (see #16274 which claims that Kyocera
// PCL6 driver does this) seem to return a too small value from
// DocumentProperties(), resulting in a crash because when we call
// it with DM_OUT_BUFFER below, memory beyond the allocated buffer
// is overwritten. So add a bit of extra memory to work around this.
dwNeeded += 1024;
LPDEVMODE tempDevMode = static_cast<LPDEVMODE>( GlobalAlloc( GMEM_FIXED | GMEM_ZEROINIT, dwNeeded ) );
// Step 2: