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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "printing/backend/win_helper.h" 5 #include "printing/backend/win_helper.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/file_version_info.h" 9 #include "base/file_version_info.h"
10 #include "base/files/file_path.h" 10 #include "base/files/file_path.h"
(...skipping 451 matching lines...) Expand 10 before | Expand all | Expand 10 after
462 scoped_ptr<DEVMODE[]> ticket = printing::XpsTicketToDevMode(printer_name, 462 scoped_ptr<DEVMODE[]> ticket = printing::XpsTicketToDevMode(printer_name,
463 xps_ticket); 463 xps_ticket);
464 if (!ticket) 464 if (!ticket)
465 return default.Pass(); 465 return default.Pass();
466 466
467 return ticket.Pass(); 467 return ticket.Pass();
468 } 468 }
469 469
470 PRINTING_EXPORT scoped_ptr<DEVMODE[]> CreateDevMode(HANDLE printer, 470 PRINTING_EXPORT scoped_ptr<DEVMODE[]> CreateDevMode(HANDLE printer,
471 DEVMODE* in) { 471 DEVMODE* in) {
472 DWORD flags = in ? (DM_IN_BUFFER) : 0; 472 LONG buffer_size = DocumentProperties(NULL, printer, L"", NULL, NULL, 0);
473 LONG buffer_size = DocumentProperties(NULL, printer, L"", NULL, in, flags);
474 if (buffer_size <= 0) 473 if (buffer_size <= 0)
475 return scoped_ptr<DEVMODE[]>(); 474 return scoped_ptr<DEVMODE[]>();
475 CHECK_GE(buffer_size, static_cast<int>(sizeof(DEVMODE)));
476 scoped_ptr<DEVMODE[]> out( 476 scoped_ptr<DEVMODE[]> out(
477 reinterpret_cast<DEVMODE*>(new uint8[buffer_size])); 477 reinterpret_cast<DEVMODE*>(new uint8[buffer_size]));
478 flags |= DM_OUT_BUFFER; 478 DWORD flags = (in ? (DM_IN_BUFFER) : 0) | DM_OUT_BUFFER;
479 if (DocumentProperties(NULL, printer, L"", out.get(), in, flags) != IDOK) 479 if (DocumentProperties(NULL, printer, L"", out.get(), in, flags) != IDOK)
480 return scoped_ptr<DEVMODE[]>(); 480 return scoped_ptr<DEVMODE[]>();
481 DCHECK_EQ(buffer_size, out.get()->dmSize + out.get()->dmDriverExtra); 481 CHECK_GE(buffer_size, out.get()->dmSize + out.get()->dmDriverExtra);
482 return out.Pass(); 482 return out.Pass();
483 } 483 }
484 484
485 } // namespace printing 485 } // namespace printing
OLDNEW
« 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