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

Side by Side Diff: chrome/common/win_util.cc

Issue 476: Clamp open file name size. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 12 years, 3 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 | « chrome/browser/views/shell_dialogs.cc ('k') | 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) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2008 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 "chrome/common/win_util.h" 5 #include "chrome/common/win_util.h"
6 6
7 #include <atlbase.h> 7 #include <atlbase.h>
8 #include <atlapp.h> 8 #include <atlapp.h>
9 #include <commdlg.h> 9 #include <commdlg.h>
10 #include <dwmapi.h> 10 #include <dwmapi.h>
(...skipping 377 matching lines...) Expand 10 before | Expand all | Expand 10 after
388 bool SaveFileAsWithFilter(HWND owner, 388 bool SaveFileAsWithFilter(HWND owner,
389 const std::wstring& suggested_name, 389 const std::wstring& suggested_name,
390 const wchar_t* filter, 390 const wchar_t* filter,
391 const std::wstring& def_ext, 391 const std::wstring& def_ext,
392 unsigned* index, 392 unsigned* index,
393 std::wstring* final_name) { 393 std::wstring* final_name) {
394 DCHECK(final_name); 394 DCHECK(final_name);
395 395
396 // Initially populated by the file component of 'suggested_name', this buffer 396 // Initially populated by the file component of 'suggested_name', this buffer
397 // will be written into by Windows when the user is done with the dialog box. 397 // will be written into by Windows when the user is done with the dialog box.
398 wchar_t file_name[MAX_PATH+1];
399 std::wstring file_part = file_util::GetFilenameFromPath(suggested_name); 398 std::wstring file_part = file_util::GetFilenameFromPath(suggested_name);
400 memcpy(file_name, 399
401 file_part.c_str(), 400 // This will clamp the number of characters copied from the supplied path
402 (file_part.length()+1) * sizeof(wchar_t)); 401 // to the value of MAX_PATH.
402 size_t name_size = std::min(file_part.length() + 1,
403 static_cast<size_t>(MAX_PATH));
404 wchar_t file_name[MAX_PATH];
405 memcpy(file_name, file_part.c_str(), name_size * sizeof(wchar_t));
406 file_name[MAX_PATH - 1] = '\0';
403 407
404 OPENFILENAME save_as; 408 OPENFILENAME save_as;
405 // We must do this otherwise the ofn's FlagsEx may be initialized to random 409 // We must do this otherwise the ofn's FlagsEx may be initialized to random
406 // junk in release builds which can cause the Places Bar not to show up! 410 // junk in release builds which can cause the Places Bar not to show up!
407 ZeroMemory(&save_as, sizeof(save_as)); 411 ZeroMemory(&save_as, sizeof(save_as));
408 save_as.lStructSize = sizeof(OPENFILENAME); 412 save_as.lStructSize = sizeof(OPENFILENAME);
409 save_as.hwndOwner = owner; 413 save_as.hwndOwner = owner;
410 save_as.hInstance = NULL; 414 save_as.hInstance = NULL;
411 415
412 save_as.lpstrFilter = &filter[0]; 416 save_as.lpstrFilter = &filter[0];
(...skipping 398 matching lines...) Expand 10 before | Expand all | Expand 10 after
811 std::wstring localized_caption; 815 std::wstring localized_caption;
812 const wchar_t* caption_ptr = caption.c_str(); 816 const wchar_t* caption_ptr = caption.c_str();
813 if (l10n_util::AdjustStringForLocaleDirection(caption, &localized_caption)) 817 if (l10n_util::AdjustStringForLocaleDirection(caption, &localized_caption))
814 caption_ptr = localized_caption.c_str(); 818 caption_ptr = localized_caption.c_str();
815 819
816 return ::MessageBox(hwnd, text_ptr, caption_ptr, actual_flags); 820 return ::MessageBox(hwnd, text_ptr, caption_ptr, actual_flags);
817 } 821 }
818 822
819 } // namespace win_util 823 } // namespace win_util
820 824
OLDNEW
« no previous file with comments | « chrome/browser/views/shell_dialogs.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698