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

Unified Diff: base/memory/shared_memory_posix.cc

Issue 17779002: Posix: fix named SHM mappings permissions. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Switch to proper low level functions. Created 7 years, 6 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 | base/memory/shared_memory_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/memory/shared_memory_posix.cc
diff --git a/base/memory/shared_memory_posix.cc b/base/memory/shared_memory_posix.cc
index 66f58487ab3ecc31bcc754706497ebbc4891fec5..0e3fb808b1dee9b5007817f66f276570fc9cf9b6 100644
--- a/base/memory/shared_memory_posix.cc
+++ b/base/memory/shared_memory_posix.cc
@@ -6,8 +6,11 @@
#include <errno.h>
#include <fcntl.h>
+#include <fcntl.h>
#include <sys/mman.h>
#include <sys/stat.h>
+#include <sys/stat.h>
+#include <sys/types.h>
#include <unistd.h>
#include "base/file_util.h"
@@ -149,12 +152,22 @@ bool SharedMemory::Create(const SharedMemoryCreateOptions& options) {
if (!FilePathForMemoryName(*options.name, &path))
return false;
- fp = file_util::OpenFile(path, "w+x");
- if (fp == NULL && options.open_existing) {
- // "w+" will truncate if it already exists.
- fp = file_util::OpenFile(path, "a+");
+ // Make sure that we don't give permissions to access this file
+ // to other users on the system.
+ const mode_t file_mode = S_IRUSR | S_IWUSR;
+ int fd;
+ // First, try to create the file.
+ fd = open(path.value().c_str(), O_RDWR | O_CREAT | O_EXCL, file_mode);
+ if (fd == -1 && options.open_existing) {
+ // If this doesn't work, try again in append mode.
+ fd = open(path.value().c_str(), O_RDWR | O_APPEND, file_mode);
Markus (顧孟勤) 2013/06/26 12:28:22 Do not pass in file_mode. That's just misleading y
jln (very slow on Chromium) 2013/07/02 02:37:06 Done.
fix_size = false;
}
+ fp = NULL;
+ if (fd >= 0) {
+ // "a+" is always appropriate: if it's a new file, a+ is similar to w+.
+ fp = fdopen(fd, "a+");
+ }
}
if (fp && fix_size) {
// Get current size.
« no previous file with comments | « no previous file | base/memory/shared_memory_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698