Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(252)

Unified Diff: printing/backend/win_helper.cc

Issue 2741483002: Check for RPCS printers and return error if Win8+ (Closed)
Patch Set: Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: printing/backend/win_helper.cc
diff --git a/printing/backend/win_helper.cc b/printing/backend/win_helper.cc
index c96e123c7d2aeab023c9d0f07b478b851004340c..db5fb33db1c6f14a9cc4077789af26124db9339d 100644
--- a/printing/backend/win_helper.cc
+++ b/printing/backend/win_helper.cc
@@ -19,6 +19,7 @@
#include "base/strings/stringprintf.h"
#include "base/strings/utf_string_conversions.h"
#include "base/win/scoped_comptr.h"
+#include "base/win/windows_version.h"
#include "printing/backend/print_backend.h"
#include "printing/backend/print_backend_consts.h"
#include "printing/backend/printing_info_win.h"
@@ -470,6 +471,24 @@ std::unique_ptr<DEVMODE, base::FreeDeleter> CreateDevModeWithColor(
return ticket;
}
+bool IsPrinterRPCSOnly(HANDLE printer) {
+ PrinterInfo5 info_5;
+ if (!info_5.Init(printer))
+ return false;
+ const wchar_t* name = info_5.get()->pPrinterName;
+ const wchar_t* port = info_5.get()->pPortName;
+ int numLanguages = DeviceCapabilities(name, port, DC_PERSONALITY, NULL, NULL);
+ if (numLanguages != 1)
+ return false;
+ wchar_t* buf = static_cast<wchar_t*>(calloc(33 * sizeof(wchar_t), 1));
Lei Zhang 2017/03/08 20:27:22 Did we forget to free |buf| ? Maybe use std::vecto
rbpotter 2017/03/08 23:25:25 Done.
+ memset(buf, 0, 33 * sizeof(wchar_t));
+ DeviceCapabilities(name, port, DC_PERSONALITY, buf, NULL);
+ static constexpr wchar_t kRPCSLanguage[] = L"RPCS";
+ if (wcscmp(buf, kRPCSLanguage) == 0)
Lei Zhang 2017/03/08 20:27:22 Just: return wcscmp(buf, kRPCSLanguage) == 0;
rbpotter 2017/03/08 23:25:25 Done.
+ return true;
+ return false;
+}
+
std::unique_ptr<DEVMODE, base::FreeDeleter> CreateDevMode(HANDLE printer,
DEVMODE* in) {
LONG buffer_size = DocumentProperties(
@@ -484,6 +503,14 @@ std::unique_ptr<DEVMODE, base::FreeDeleter> CreateDevMode(HANDLE printer,
std::unique_ptr<DEVMODE, base::FreeDeleter> out(
reinterpret_cast<DEVMODE*>(calloc(buffer_size, 1)));
DWORD flags = (in ? (DM_IN_BUFFER) : 0) | DM_OUT_BUFFER;
+
+ // Check for RPCS drivers on Windows 8+ as DocumentProperties will crash if
+ // called on one of these printers. See crbug.com/679160
+ if (base::win::GetVersion() >= base::win::VERSION_WIN8 &&
+ IsPrinterRPCSOnly(printer)) {
+ return std::unique_ptr<DEVMODE, base::FreeDeleter>();
+ }
+
if (DocumentProperties(
NULL, printer, const_cast<wchar_t*>(L""), out.get(), in, flags) !=
IDOK) {

Powered by Google App Engine
This is Rietveld 408576698