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

Unified Diff: printing/backend/win_helper.cc

Issue 182273003: Added more checks for buffer size to crash safely in case of incorrect driver behavior. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 10 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: printing/backend/win_helper.cc
diff --git a/printing/backend/win_helper.cc b/printing/backend/win_helper.cc
index a16228b703da699259bc962c1069665487632c6c..3405114029482dd1ed3e55c4637eb3327be815f1 100644
--- a/printing/backend/win_helper.cc
+++ b/printing/backend/win_helper.cc
@@ -469,16 +469,16 @@ scoped_ptr<DEVMODE[]> CreateDevModeWithColor(HANDLE printer,
PRINTING_EXPORT scoped_ptr<DEVMODE[]> CreateDevMode(HANDLE printer,
DEVMODE* in) {
- DWORD flags = in ? (DM_IN_BUFFER) : 0;
- LONG buffer_size = DocumentProperties(NULL, printer, L"", NULL, in, flags);
+ LONG buffer_size = DocumentProperties(NULL, printer, L"", NULL, NULL, 0);
if (buffer_size <= 0)
return scoped_ptr<DEVMODE[]>();
+ CHECK_GE(buffer_size, static_cast<int>(sizeof(DEVMODE)));
scoped_ptr<DEVMODE[]> out(
reinterpret_cast<DEVMODE*>(new uint8[buffer_size]));
- flags |= DM_OUT_BUFFER;
+ DWORD flags = (in ? (DM_IN_BUFFER) : 0) | DM_OUT_BUFFER;
if (DocumentProperties(NULL, printer, L"", out.get(), in, flags) != IDOK)
return scoped_ptr<DEVMODE[]>();
- DCHECK_EQ(buffer_size, out.get()->dmSize + out.get()->dmDriverExtra);
+ CHECK_GE(buffer_size, out.get()->dmSize + out.get()->dmDriverExtra);
return out.Pass();
}
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698