From b806e13001b6908e3aa1180a8a32c55431e79f7f Mon Sep 17 00:00:00 2001 From: Jeremy White Date: Wed, 23 Dec 2009 11:21:32 -0600 Subject: [PATCH] winspool: Correctly zero printer driver buffer on failure, with tests. --- dlls/winspool.drv/info.c | 7 ++++++- dlls/winspool.drv/tests/info.c | 8 ++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/dlls/winspool.drv/info.c b/dlls/winspool.drv/info.c index a2dd79800f9..4993a7823e3 100644 --- a/dlls/winspool.drv/info.c +++ b/dlls/winspool.drv/info.c @@ -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,8 +4467,11 @@ 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, cbBuf, pcbNeeded); diff --git a/dlls/winspool.drv/tests/info.c b/dlls/winspool.drv/tests/info.c index 5ab0ccd41f0..f3b2d78a469 100644 --- a/dlls/winspool.drv/tests/info.c +++ b/dlls/winspool.drv/tests/info.c @@ -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);