Commit b806e130 authored by Jeremy White's avatar Jeremy White Committed by Alexandre Julliard

winspool: Correctly zero printer driver buffer on failure, with tests.

parent 09401dd4
...@@ -4388,6 +4388,8 @@ BOOL WINAPI GetPrinterDriverW(HANDLE hPrinter, LPWSTR pEnvironment, ...@@ -4388,6 +4388,8 @@ BOOL WINAPI GetPrinterDriverW(HANDLE hPrinter, LPWSTR pEnvironment,
TRACE("(%p,%s,%d,%p,%d,%p)\n",hPrinter,debugstr_w(pEnvironment), TRACE("(%p,%s,%d,%p,%d,%p)\n",hPrinter,debugstr_w(pEnvironment),
Level,pDriverInfo,cbBuf, pcbNeeded); Level,pDriverInfo,cbBuf, pcbNeeded);
if (cbBuf > 0)
ZeroMemory(pDriverInfo, cbBuf);
if (!(name = get_opened_printer_name(hPrinter))) { if (!(name = get_opened_printer_name(hPrinter))) {
SetLastError(ERROR_INVALID_HANDLE); SetLastError(ERROR_INVALID_HANDLE);
...@@ -4465,8 +4467,11 @@ BOOL WINAPI GetPrinterDriverA(HANDLE hPrinter, LPSTR pEnvironment, ...@@ -4465,8 +4467,11 @@ BOOL WINAPI GetPrinterDriverA(HANDLE hPrinter, LPSTR pEnvironment,
LPBYTE buf = NULL; LPBYTE buf = NULL;
if (cbBuf) if (cbBuf)
{
ZeroMemory(pDriverInfo, cbBuf);
buf = HeapAlloc(GetProcessHeap(), 0, cbBuf); buf = HeapAlloc(GetProcessHeap(), 0, cbBuf);
}
pwstrEnvW = asciitounicode(&pEnvW, pEnvironment); pwstrEnvW = asciitounicode(&pEnvW, pEnvironment);
ret = GetPrinterDriverW(hPrinter, pwstrEnvW, Level, buf, ret = GetPrinterDriverW(hPrinter, pwstrEnvW, Level, buf,
cbBuf, pcbNeeded); cbBuf, pcbNeeded);
......
...@@ -2414,6 +2414,14 @@ static void test_GetPrinterDriver(void) ...@@ -2414,6 +2414,14 @@ static void test_GetPrinterDriver(void)
/* XP allocates memory for both ANSI and unicode names */ /* XP allocates memory for both ANSI and unicode names */
ok(filled >= calculated,"calculated %d != filled %d\n", calculated, filled); 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); HeapFree(GetProcessHeap(), 0, buf);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment