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

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: Write the uid and gid maps in the pre_exec_delegate. 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
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..81e096c1262d706ab3e1b3d922fc8b85f0a49c10 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 {
@@ -38,11 +38,14 @@ bool NamespaceUtils::WriteToIdMapFile(const char* map_file, generic_id_t id) {
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);
+
+ // This function needs to be async-signal-safe, as it is called in between
jln (very slow on Chromium) 2015/02/03 01:14:30 Add this as a comment to the function instead.
rickyz (no longer on Chrome) 2015/02/03 01:27:22 Done.
+ // fork and exec.
+ 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.get(), mapping, len));
+ return rc == len;
}
// static

Powered by Google App Engine
This is Rietveld 408576698