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

Side by Side Diff: printing/backend/win_helper.cc

Issue 644463002: Zeroes buffer for DocumentProperti (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Wed Oct 8 13:17:15 PDT 2014 Created 6 years, 2 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
« 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 459 matching lines...) Expand 10 before | Expand all | Expand 10 after
470 return ticket.Pass(); 470 return ticket.Pass();
471 } 471 }
472 472
473 scoped_ptr<DEVMODE, base::FreeDeleter> CreateDevMode(HANDLE printer, 473 scoped_ptr<DEVMODE, base::FreeDeleter> CreateDevMode(HANDLE printer,
474 DEVMODE* in) { 474 DEVMODE* in) {
475 LONG buffer_size = DocumentProperties( 475 LONG buffer_size = DocumentProperties(
476 NULL, printer, const_cast<wchar_t*>(L""), NULL, NULL, 0); 476 NULL, printer, const_cast<wchar_t*>(L""), NULL, NULL, 0);
477 if (buffer_size < static_cast<int>(sizeof(DEVMODE))) 477 if (buffer_size < static_cast<int>(sizeof(DEVMODE)))
478 return scoped_ptr<DEVMODE, base::FreeDeleter>(); 478 return scoped_ptr<DEVMODE, base::FreeDeleter>();
479 scoped_ptr<DEVMODE, base::FreeDeleter> out( 479 scoped_ptr<DEVMODE, base::FreeDeleter> out(
480 reinterpret_cast<DEVMODE*>(malloc(buffer_size))); 480 reinterpret_cast<DEVMODE*>(calloc(buffer_size, 1)));
481 DWORD flags = (in ? (DM_IN_BUFFER) : 0) | DM_OUT_BUFFER; 481 DWORD flags = (in ? (DM_IN_BUFFER) : 0) | DM_OUT_BUFFER;
482 if (DocumentProperties( 482 if (DocumentProperties(
483 NULL, printer, const_cast<wchar_t*>(L""), out.get(), in, flags) != 483 NULL, printer, const_cast<wchar_t*>(L""), out.get(), in, flags) !=
484 IDOK) { 484 IDOK) {
485 return scoped_ptr<DEVMODE, base::FreeDeleter>(); 485 return scoped_ptr<DEVMODE, base::FreeDeleter>();
486 } 486 }
487 CHECK_GE(buffer_size, out.get()->dmSize + out.get()->dmDriverExtra); 487 int size = out->dmSize;
488 int extra_size = out->dmDriverExtra;
489 CHECK_GE(buffer_size, size + extra_size);
488 return out.Pass(); 490 return out.Pass();
489 } 491 }
490 492
491 scoped_ptr<DEVMODE, base::FreeDeleter> PromptDevMode( 493 scoped_ptr<DEVMODE, base::FreeDeleter> PromptDevMode(
492 HANDLE printer, 494 HANDLE printer,
493 const base::string16& printer_name, 495 const base::string16& printer_name,
494 DEVMODE* in, 496 DEVMODE* in,
495 HWND window, 497 HWND window,
496 bool* canceled) { 498 bool* canceled) {
497 LONG buffer_size = 499 LONG buffer_size =
498 DocumentProperties(window, 500 DocumentProperties(window,
499 printer, 501 printer,
500 const_cast<wchar_t*>(printer_name.c_str()), 502 const_cast<wchar_t*>(printer_name.c_str()),
501 NULL, 503 NULL,
502 NULL, 504 NULL,
503 0); 505 0);
504 if (buffer_size < static_cast<int>(sizeof(DEVMODE))) 506 if (buffer_size < static_cast<int>(sizeof(DEVMODE)))
505 return scoped_ptr<DEVMODE, base::FreeDeleter>(); 507 return scoped_ptr<DEVMODE, base::FreeDeleter>();
506 scoped_ptr<DEVMODE, base::FreeDeleter> out( 508 scoped_ptr<DEVMODE, base::FreeDeleter> out(
507 reinterpret_cast<DEVMODE*>(malloc(buffer_size))); 509 reinterpret_cast<DEVMODE*>(calloc(buffer_size, 1)));
508 DWORD flags = (in ? (DM_IN_BUFFER) : 0) | DM_OUT_BUFFER | DM_IN_PROMPT; 510 DWORD flags = (in ? (DM_IN_BUFFER) : 0) | DM_OUT_BUFFER | DM_IN_PROMPT;
509 LONG result = DocumentProperties(window, 511 LONG result = DocumentProperties(window,
510 printer, 512 printer,
511 const_cast<wchar_t*>(printer_name.c_str()), 513 const_cast<wchar_t*>(printer_name.c_str()),
512 out.get(), 514 out.get(),
513 in, 515 in,
514 flags); 516 flags);
515 if (canceled) 517 if (canceled)
516 *canceled = (result == IDCANCEL); 518 *canceled = (result == IDCANCEL);
517 if (result != IDOK) 519 if (result != IDOK)
518 return scoped_ptr<DEVMODE, base::FreeDeleter>(); 520 return scoped_ptr<DEVMODE, base::FreeDeleter>();
519 CHECK_GE(buffer_size, out.get()->dmSize + out.get()->dmDriverExtra); 521 int size = out->dmSize;
522 int extra_size = out->dmDriverExtra;
523 CHECK_GE(buffer_size, size + extra_size);
520 return out.Pass(); 524 return out.Pass();
521 } 525 }
522 526
523 } // namespace printing 527 } // 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