diff options
author | beng@google.com <beng@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-09-05 21:47:34 +0000 |
---|---|---|
committer | beng@google.com <beng@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-09-05 21:47:34 +0000 |
commit | 783734c050e524c4ba6abd624d5cd487b596da26 (patch) | |
tree | 4b469af91c9e2b561c222a4b1ab2364472b4f22d /chrome/common/win_util.cc | |
parent | c2cbeb9dd8aec543d5c6f0fe2aa99c1f8c655351 (diff) | |
download | chromium_src-783734c050e524c4ba6abd624d5cd487b596da26.zip chromium_src-783734c050e524c4ba6abd624d5cd487b596da26.tar.gz chromium_src-783734c050e524c4ba6abd624d5cd487b596da26.tar.bz2 |
Clamp open file name size.
B=1362425
Review URL: http://codereview.chromium.org/476
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@1810 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/common/win_util.cc')
-rw-r--r-- | chrome/common/win_util.cc | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/chrome/common/win_util.cc b/chrome/common/win_util.cc index 7bcd55d..36e1f86 100644 --- a/chrome/common/win_util.cc +++ b/chrome/common/win_util.cc @@ -395,11 +395,15 @@ bool SaveFileAsWithFilter(HWND owner, // Initially populated by the file component of 'suggested_name', this buffer // will be written into by Windows when the user is done with the dialog box. - wchar_t file_name[MAX_PATH+1]; std::wstring file_part = file_util::GetFilenameFromPath(suggested_name); - memcpy(file_name, - file_part.c_str(), - (file_part.length()+1) * sizeof(wchar_t)); + + // This will clamp the number of characters copied from the supplied path + // to the value of MAX_PATH. + size_t name_size = std::min(file_part.length() + 1, + static_cast<size_t>(MAX_PATH)); + wchar_t file_name[MAX_PATH]; + memcpy(file_name, file_part.c_str(), name_size * sizeof(wchar_t)); + file_name[MAX_PATH - 1] = '\0'; OPENFILENAME save_as; // We must do this otherwise the ofn's FlagsEx may be initialized to random |