winspool: Correctly zero printer driver buffer on failure, with tests.
This commit is contained in:
parent
09401dd4b1
commit
b806e13001
|
@ -4388,6 +4388,8 @@ BOOL WINAPI GetPrinterDriverW(HANDLE hPrinter, LPWSTR pEnvironment,
|
|||
TRACE("(%p,%s,%d,%p,%d,%p)\n",hPrinter,debugstr_w(pEnvironment),
|
||||
Level,pDriverInfo,cbBuf, pcbNeeded);
|
||||
|
||||
if (cbBuf > 0)
|
||||
ZeroMemory(pDriverInfo, cbBuf);
|
||||
|
||||
if (!(name = get_opened_printer_name(hPrinter))) {
|
||||
SetLastError(ERROR_INVALID_HANDLE);
|
||||
|
@ -4465,7 +4467,10 @@ BOOL WINAPI GetPrinterDriverA(HANDLE hPrinter, LPSTR pEnvironment,
|
|||
LPBYTE buf = NULL;
|
||||
|
||||
if (cbBuf)
|
||||
{
|
||||
ZeroMemory(pDriverInfo, cbBuf);
|
||||
buf = HeapAlloc(GetProcessHeap(), 0, cbBuf);
|
||||
}
|
||||
|
||||
pwstrEnvW = asciitounicode(&pEnvW, pEnvironment);
|
||||
ret = GetPrinterDriverW(hPrinter, pwstrEnvW, Level, buf,
|
||||
|
|
|
@ -2414,6 +2414,14 @@ static void test_GetPrinterDriver(void)
|
|||
|
||||
/* XP allocates memory for both ANSI and unicode names */
|
||||
ok(filled >= calculated,"calculated %d != filled %d\n", calculated, filled);
|
||||
|
||||
/* Obscure test - demonstrate that Windows zero fills the buffer, even on failure */
|
||||
if (di_2->pDataFile)
|
||||
{
|
||||
ret = GetPrinterDriver(hprn, NULL, level, buf, needed - 2, &filled);
|
||||
ok(!ret, "level %d: GetPrinterDriver succeeded with less buffer than it should\n", level);
|
||||
ok(di_2->pDataFile == NULL, "Even on failure, GetPrinterDriver clears the buffer to zeros\n");
|
||||
}
|
||||
}
|
||||
|
||||
HeapFree(GetProcessHeap(), 0, buf);
|
||||
|
|
Loading…
Reference in New Issue