diff options
author | jeremy@chromium.org <jeremy@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-07-14 16:48:05 +0000 |
---|---|---|
committer | jeremy@chromium.org <jeremy@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-07-14 16:48:05 +0000 |
commit | 12d3484a8dd1b6955b3554825ba9f0a3fea97dcc (patch) | |
tree | 2d65dbd3492b5b199d992a4f42a5410cb7240dae /chrome/common | |
parent | 0b4d3382c817b4c572db7b13b2a90f9a56cb7f8f (diff) | |
download | chromium_src-12d3484a8dd1b6955b3554825ba9f0a3fea97dcc.zip chromium_src-12d3484a8dd1b6955b3554825ba9f0a3fea97dcc.tar.gz chromium_src-12d3484a8dd1b6955b3554825ba9f0a3fea97dcc.tar.bz2 |
Revert r52326 since it's causing unit tests to fail.
Review URL: http://codereview.chromium.org/2958011
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@52330 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/common')
-rw-r--r-- | chrome/common/sandbox_mac.h | 5 | ||||
-rw-r--r-- | chrome/common/sandbox_mac.mm | 46 | ||||
-rw-r--r-- | chrome/common/sandbox_mac_diraccess_unittest.mm | 2 |
3 files changed, 14 insertions, 39 deletions
diff --git a/chrome/common/sandbox_mac.h b/chrome/common/sandbox_mac.h index 249eaa3..8065298 100644 --- a/chrome/common/sandbox_mac.h +++ b/chrome/common/sandbox_mac.h @@ -50,11 +50,6 @@ void SandboxWarmup(); bool EnableSandbox(SandboxProcessType sandbox_type, const FilePath& allowed_dir); -// Convert provided path into a "canonical" path matching what the Sandbox -// expects i.e. one without symlinks. -// This path is not necessarily unique e.g. in the face of hardlinks. -void GetCanonicalSandboxPath(FilePath* path); - } // namespace sandbox #endif // CHROME_COMMON_SANDBOX_MAC_H_ diff --git a/chrome/common/sandbox_mac.mm b/chrome/common/sandbox_mac.mm index 8253c55..bc0929e 100644 --- a/chrome/common/sandbox_mac.mm +++ b/chrome/common/sandbox_mac.mm @@ -10,7 +10,6 @@ extern "C" { #include <sandbox.h> } -#include <sys/param.h> #include "base/basictypes.h" #include "base/command_line.h" @@ -119,26 +118,27 @@ bool QuotePlainString(const std::string& str_utf8, std::string* dst) { // // Returns: true on success, false otherwise. bool QuoteStringForRegex(const std::string& str_utf8, std::string* dst) { - // Characters with special meanings in sandbox profile syntax. - // Note: ]} are notably absent from this list although in practice escaping - // them has no ill effect. + // List of chars with special meaning to regex. + // This list is derived from http://perldoc.perl.org/perlre.html . const char regex_special_chars[] = { '\\', // Metacharacters '^', '.', - '[', '$', + '|', '(', ')', - '|', + '[', + ']', // Quantifiers '*', '+', '?', '{', + '}', }; // Anchor regex at start of path. @@ -345,11 +345,14 @@ bool EnableSandbox(SandboxProcessType sandbox_type, // needed so the caller doesn't need to worry about things like /var // being a link to /private/var (like in the paths CreateNewTempDirectory() // returns). - FilePath allowed_dir_canonical(allowed_dir); - GetCanonicalSandboxPath(&allowed_dir_canonical); + FilePath allowed_dir_absolute(allowed_dir); + if (!file_util::AbsolutePath(&allowed_dir_absolute)) { + PLOG(FATAL) << "Failed to resolve absolute path"; + return false; + } std::string allowed_dir_escaped; - if (!QuoteStringForRegex(allowed_dir_canonical.value(), + if (!QuoteStringForRegex(allowed_dir_absolute.value(), &allowed_dir_escaped)) { LOG(FATAL) << "Regex string quoting failed " << allowed_dir.value(); return false; @@ -381,12 +384,8 @@ bool EnableSandbox(SandboxProcessType sandbox_type, // If we ever need this on pre-10.6 OSs then we'll have to rethink the // surrounding sandbox syntax. std::string home_dir = base::SysNSStringToUTF8(NSHomeDirectory()); - - FilePath home_dir_canonical(home_dir); - GetCanonicalSandboxPath(&home_dir_canonical); - std::string home_dir_escaped; - if (!QuotePlainString(home_dir_canonical.value(), &home_dir_escaped)) { + if (!QuotePlainString(home_dir, &home_dir_escaped)) { LOG(FATAL) << "Sandbox string quoting failed"; return false; } @@ -412,23 +411,4 @@ bool EnableSandbox(SandboxProcessType sandbox_type, return success; } -void GetCanonicalSandboxPath(FilePath* path) { - int fd = HANDLE_EINTR(open(path->value().c_str(), O_RDONLY)); - if (fd < 0) { - PLOG(FATAL) << "GetCanonicalSandboxPath() failed for: " - << path->value(); - return; - } - file_util::ScopedFD file_closer(&fd); - - FilePath::CharType canonical_path[MAXPATHLEN]; - if (HANDLE_EINTR(fcntl(fd, F_GETPATH, canonical_path)) != 0) { - PLOG(FATAL) << "GetCanonicalSandboxPath() failed for: " - << path->value(); - return; - } - - *path = FilePath(canonical_path); -} - } // namespace sandbox diff --git a/chrome/common/sandbox_mac_diraccess_unittest.mm b/chrome/common/sandbox_mac_diraccess_unittest.mm index f356453..71eff73 100644 --- a/chrome/common/sandbox_mac_diraccess_unittest.mm +++ b/chrome/common/sandbox_mac_diraccess_unittest.mm @@ -147,7 +147,7 @@ TEST_F(MacDirAccessSandboxTest, SandboxAccess) { // This step is important on OS X since the sandbox only understands "real" // paths and the paths CreateNewTempDirectory() returns are empirically in // /var which is a symlink to /private/var . - sandbox::GetCanonicalSandboxPath(&tmp_dir); + ASSERT_TRUE(file_util::AbsolutePath(&tmp_dir)); ScopedDirectory cleanup(&tmp_dir); const char* sandbox_dir_cases[] = { |