From efe693e607e325cd00220f2d271d067a70e88b91 Mon Sep 17 00:00:00 2001 From: Piotr Caban Date: Tue, 25 Oct 2022 15:49:18 +0200 Subject: [PATCH] winspool: Implement print processor validation in AddPrinter. --- dlls/winspool.drv/info.c | 33 ++++++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/dlls/winspool.drv/info.c b/dlls/winspool.drv/info.c index e58ae925c2b..258d67c5788 100644 --- a/dlls/winspool.drv/info.c +++ b/dlls/winspool.drv/info.c @@ -2568,6 +2568,37 @@ static void set_devices_and_printerports(PRINTER_INFO_2W *pi) } } +static BOOL validate_print_proc(WCHAR *server, const WCHAR *name) +{ + PRINTPROCESSOR_INFO_1W *ppi; + DWORD size, i, no; + + if (!EnumPrintProcessorsW(server, NULL, 1, NULL, 0, &size, &no) + && GetLastError() != ERROR_INSUFFICIENT_BUFFER) + { + return FALSE; + } + ppi = malloc(size); + if (!ppi) + { + SetLastError(ERROR_OUTOFMEMORY); + return FALSE; + } + if (!EnumPrintProcessorsW(server, NULL, 1, (BYTE*)ppi, size, &size, &no)) + { + free(ppi); + return FALSE; + } + + for (i = 0; i < no; i++) + { + if (!wcsicmp(ppi[i].pName, name)) + break; + } + free(ppi); + return i != no; +} + /***************************************************************************** * AddPrinterW [WINSPOOL.@] */ @@ -2628,7 +2659,7 @@ HANDLE WINAPI AddPrinterW(LPWSTR pName, DWORD Level, LPBYTE pPrinter) RegCloseKey(hkeyDriver); RegCloseKey(hkeyDrivers); - if (wcsicmp( pi->pPrintProcessor, L"WinPrint" )) + if (!validate_print_proc(pName, pi->pPrintProcessor)) { FIXME("Can't find processor %s\n", debugstr_w(pi->pPrintProcessor)); SetLastError(ERROR_UNKNOWN_PRINTPROCESSOR);