summaryrefslogtreecommitdiffstats
path: root/sandbox
diff options
context:
space:
mode:
authorjorgelo@chromium.org <jorgelo@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-07-09 21:47:27 +0000
committerjorgelo@chromium.org <jorgelo@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-07-09 21:47:27 +0000
commit13c8a5e4fb8e78a28e725f54a62d56e83e887b7a (patch)
tree071a5b96529a5f345873c2ee08bbd1a60b702792 /sandbox
parenta1e8742047026225fb3281af6bd358bab417ce35 (diff)
downloadchromium_src-13c8a5e4fb8e78a28e725f54a62d56e83e887b7a.zip
chromium_src-13c8a5e4fb8e78a28e725f54a62d56e83e887b7a.tar.gz
chromium_src-13c8a5e4fb8e78a28e725f54a62d56e83e887b7a.tar.bz2
Avoid std::string copying in GetFileNameInWhitelist.
BUG=256452 TEST=sandbox_linux_unittests passes. TEST=about:gpu shows "Sandboxed: true", browser works. NOTRY=true Review URL: https://chromiumcodereview.appspot.com/18337010 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@210651 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'sandbox')
-rw-r--r--sandbox/linux/services/broker_process.cc19
1 files changed, 12 insertions, 7 deletions
diff --git a/sandbox/linux/services/broker_process.cc b/sandbox/linux/services/broker_process.cc
index d2302ea..7999e77 100644
--- a/sandbox/linux/services/broker_process.cc
+++ b/sandbox/linux/services/broker_process.cc
@@ -53,7 +53,7 @@ static const int kCurrentProcessOpenFlagsMask = O_CLOEXEC;
// async signal safe if |file_to_open| is NULL.
// TODO(jln): assert signal safety.
bool GetFileNameInWhitelist(const std::vector<std::string>& allowed_file_names,
- const std::string& requested_filename,
+ const char* requested_filename,
const char** file_to_open) {
if (file_to_open && *file_to_open) {
// Make sure that callers never pass a non-empty string. In case callers
@@ -62,13 +62,17 @@ bool GetFileNameInWhitelist(const std::vector<std::string>& allowed_file_names,
RAW_LOG(FATAL, "*file_to_open should be NULL");
return false;
}
+
+ // Look for |requested_filename| in |allowed_file_names|.
+ // We don't use ::find() because it takes a std::string and
+ // the conversion allocates memory.
std::vector<std::string>::const_iterator it;
- it = std::find(allowed_file_names.begin(), allowed_file_names.end(),
- requested_filename);
- if (it < allowed_file_names.end()) { // requested_filename was found?
- if (file_to_open)
- *file_to_open = it->c_str();
- return true;
+ for (it = allowed_file_names.begin(); it != allowed_file_names.end(); it++) {
+ if (strcmp(requested_filename, it->c_str()) == 0) {
+ if (file_to_open)
+ *file_to_open = it->c_str();
+ return true;
+ }
}
return false;
}
@@ -393,6 +397,7 @@ void BrokerProcess::AccessFileForIPC(const std::string& requested_filename,
const char* file_to_access = NULL;
const bool safe_to_access_file = GetFileNameIfAllowedToAccess(
requested_filename.c_str(), mode, &file_to_access);
+
if (safe_to_access_file) {
CHECK(file_to_access);
int access_ret = access(file_to_access, mode);