Jeremy White : winspool: Correctly zero printer driver buffer on failure, with tests.
Alexandre Julliard
julliard at winehq.org
Thu Dec 24 10:27:17 CST 2009
Module: wine
Branch: master
Commit: b806e13001b6908e3aa1180a8a32c55431e79f7f
URL: http://source.winehq.org/git/wine.git/?a=commit;h=b806e13001b6908e3aa1180a8a32c55431e79f7f
Author: Jeremy White <jwhite at codeweavers.com>
Date: Wed Dec 23 11:21:32 2009 -0600
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 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-cvs
mailing list