[winspool 2/2] Correctly zero printer driver buffer on failure, with tests.
Jeremy White
jwhite at codeweavers.com
Wed Dec 23 11:21:32 CST 2009
---
dlls/winspool.drv/info.c | 7 ++++++-
dlls/winspool.drv/tests/info.c | 8 ++++++++
2 files changed, 14 insertions(+), 1 deletions(-)
diff --git a/dlls/winspool.drv/info.c b/dlls/winspool.drv/info.c
index a2dd798..4993a78 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 5ab0ccd..f3b2d78 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);
More information about the wine-patches
mailing list