| 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
|
|
|