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

Unified Diff: sandbox/linux/services/namespace_utils.cc

Issue 881733002: Add namespace sandbox class. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Last round of comments. Created 5 years, 11 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 | « sandbox/linux/services/namespace_utils.h ('k') | sandbox/linux/services/namespace_utils_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: sandbox/linux/services/namespace_utils.cc
diff --git a/sandbox/linux/services/namespace_utils.cc b/sandbox/linux/services/namespace_utils.cc
index f03fe4080aa32ea49e383e784463dd30d24c8de2..cf4c37a58033d6d3cb2fcc60461e9e7af30e88a7 100644
--- a/sandbox/linux/services/namespace_utils.cc
+++ b/sandbox/linux/services/namespace_utils.cc
@@ -18,7 +18,7 @@
#include "base/logging.h"
#include "base/posix/eintr_wrapper.h"
#include "base/process/launch.h"
-#include "base/strings/stringprintf.h"
+#include "base/strings/safe_sprintf.h"
#include "base/third_party/valgrind/valgrind.h"
namespace sandbox {
@@ -31,18 +31,23 @@ bool IsRunningOnValgrind() {
// static
bool NamespaceUtils::WriteToIdMapFile(const char* map_file, generic_id_t id) {
- base::ScopedFD fd(HANDLE_EINTR(open(map_file, O_WRONLY)));
- if (!fd.is_valid()) {
+ // This function needs to be async-signal-safe, as it may be called in between
+ // fork and exec.
+
+ int fd = HANDLE_EINTR(open(map_file, O_WRONLY));
+ if (fd == -1) {
return false;
}
const generic_id_t inside_id = id;
const generic_id_t outside_id = id;
- const std::string mapping =
- base::StringPrintf("%d %d 1\n", inside_id, outside_id);
- const size_t len = mapping.size();
- const ssize_t rc = HANDLE_EINTR(write(fd.get(), mapping.c_str(), len));
- return rc == static_cast<ssize_t>(len);
+
+ char mapping[64];
+ ssize_t len =
+ base::strings::SafeSPrintf(mapping, "%d %d 1\n", inside_id, outside_id);
+ const ssize_t rc = HANDLE_EINTR(write(fd, mapping, len));
+ RAW_CHECK(IGNORE_EINTR(close(fd)) == 0);
+ return rc == len;
}
// static
« no previous file with comments | « sandbox/linux/services/namespace_utils.h ('k') | sandbox/linux/services/namespace_utils_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698