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

Unified Diff: chrome/common/sandbox_mac.mm

Issue 3022005: Recommit - r52326 - Mac: Use canonicalization rather than absolute paths for sandbox. (Closed)
Patch Set: Created 10 years, 5 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 | « chrome/common/sandbox_mac.h ('k') | chrome/common/sandbox_mac_diraccess_unittest.mm » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/common/sandbox_mac.mm
diff --git a/chrome/common/sandbox_mac.mm b/chrome/common/sandbox_mac.mm
index bc0929e088b7331ff313db465a5630b2f5a8be0b..3d2985c0d96ae74085ce0d86c4640212d2568702 100644
--- a/chrome/common/sandbox_mac.mm
+++ b/chrome/common/sandbox_mac.mm
@@ -10,6 +10,7 @@
extern "C" {
#include <sandbox.h>
}
+#include <sys/param.h>
#include "base/basictypes.h"
#include "base/command_line.h"
@@ -118,20 +119,19 @@ 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) {
- // List of chars with special meaning to regex.
- // This list is derived from http://perldoc.perl.org/perlre.html .
+ // Characters with special meanings in sandbox profile syntax.
const char regex_special_chars[] = {
'\\',
// Metacharacters
'^',
'.',
+ '[',
+ ']',
'$',
- '|',
'(',
')',
- '[',
- ']',
+ '|',
// Quantifiers
'*',
@@ -345,14 +345,11 @@ 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_absolute(allowed_dir);
- if (!file_util::AbsolutePath(&allowed_dir_absolute)) {
- PLOG(FATAL) << "Failed to resolve absolute path";
- return false;
- }
+ FilePath allowed_dir_canonical(allowed_dir);
+ GetCanonicalSandboxPath(&allowed_dir_canonical);
std::string allowed_dir_escaped;
- if (!QuoteStringForRegex(allowed_dir_absolute.value(),
+ if (!QuoteStringForRegex(allowed_dir_canonical.value(),
&allowed_dir_escaped)) {
LOG(FATAL) << "Regex string quoting failed " << allowed_dir.value();
return false;
@@ -384,8 +381,12 @@ 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, &home_dir_escaped)) {
+ if (!QuotePlainString(home_dir_canonical.value(), &home_dir_escaped)) {
LOG(FATAL) << "Sandbox string quoting failed";
return false;
}
@@ -411,4 +412,23 @@ 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
« no previous file with comments | « chrome/common/sandbox_mac.h ('k') | chrome/common/sandbox_mac_diraccess_unittest.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698