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

Unified Diff: chrome/browser/views/shell_dialogs.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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | chrome/common/win_util.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/views/shell_dialogs.cc
===================================================================
--- chrome/browser/views/shell_dialogs.cc (revision 1800)
+++ chrome/browser/views/shell_dialogs.cc (working copy)
@@ -340,8 +340,13 @@
ofn.lStructSize = sizeof(ofn);
ofn.hwndOwner = owner;
+ // This will clamp the number of characters copied from the supplied path
+ // to the value of MAX_PATH.
+ size_t name_size = std::min(path->length() + 1,
+ static_cast<size_t>(MAX_PATH));
wchar_t filename[MAX_PATH];
- memcpy(filename, path->c_str(), (path->length()+1) * sizeof(wchar_t));
+ memcpy(filename, path->c_str(), name_size * sizeof(wchar_t));
+ filename[MAX_PATH - 1] = '\0';
ofn.lpstrFile = filename;
ofn.nMaxFile = MAX_PATH;
« no previous file with comments | « no previous file | chrome/common/win_util.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698