Browse Source

fix: use shorter paths for creating singleton sockets (#31608)

Robo 3 years ago
parent
commit
3bf42593ba

+ 1 - 1
patches/chromium/feat_add_data_parameter_to_processsingleton.patch

@@ -61,7 +61,7 @@ index eec994c4252f17d9c9c41e66d5dae6509ed98a18..e538c9b76da4d4435e10cd3848438446
  #if defined(OS_WIN)
    bool EscapeVirtualization(const base::FilePath& user_data_dir);
 diff --git a/chrome/browser/process_singleton_posix.cc b/chrome/browser/process_singleton_posix.cc
-index 727333dd6abec99643e31bc77ed2cc8f3d5a0a0b..e5361397f78636816507355e7db6a9e55e6ed234 100644
+index a04d139f958a7aaef9b96e8c29317ccf7c97f009..29188668a69047b3ad3bebd1f0057565a330b509 100644
 --- a/chrome/browser/process_singleton_posix.cc
 +++ b/chrome/browser/process_singleton_posix.cc
 @@ -567,6 +567,7 @@ class ProcessSingleton::LinuxWatcher

+ 17 - 12
patches/chromium/process_singleton.patch

@@ -76,7 +76,7 @@ index 0d7c1db6489d95a40c66808c3f838b0740e46ff6..eec994c4252f17d9c9c41e66d5dae650
  
  #if defined(OS_MAC)
 diff --git a/chrome/browser/process_singleton_posix.cc b/chrome/browser/process_singleton_posix.cc
-index 4547eb8563e1af57aad991d9d1e2cf02c778380a..727333dd6abec99643e31bc77ed2cc8f3d5a0a0b 100644
+index 4547eb8563e1af57aad991d9d1e2cf02c778380a..a04d139f958a7aaef9b96e8c29317ccf7c97f009 100644
 --- a/chrome/browser/process_singleton_posix.cc
 +++ b/chrome/browser/process_singleton_posix.cc
 @@ -80,6 +80,7 @@
@@ -171,7 +171,7 @@ index 4547eb8563e1af57aad991d9d1e2cf02c778380a..727333dd6abec99643e31bc77ed2cc8f
  ProcessSingleton::NotifyResult
  ProcessSingleton::NotifyOtherProcessWithTimeoutOrCreate(
      const base::CommandLine& command_line,
-@@ -999,12 +1039,26 @@ bool ProcessSingleton::Create() {
+@@ -999,14 +1039,32 @@ bool ProcessSingleton::Create() {
  #endif
    }
  
@@ -180,15 +180,15 @@ index 4547eb8563e1af57aad991d9d1e2cf02c778380a..727333dd6abec99643e31bc77ed2cc8f
 -  // do not support Unix domain sockets.
 -  if (!socket_dir_.CreateUniqueTempDir()) {
 -    LOG(ERROR) << "Failed to create socket directory.";
--    return false;
++  base::FilePath tmp_dir;
++  if (!base::GetTempDir(&tmp_dir)) {
++    LOG(ERROR) << "Failed to get temporary directory.";
+     return false;
+   }
+ 
 +  if (IsAppSandboxed()) {
 +    // For sandboxed applications, the tmp dir could be too long to fit
 +    // addr->sun_path, so we need to make it as short as possible.
-+    base::FilePath tmp_dir;
-+    if (!base::GetTempDir(&tmp_dir)) {
-+      LOG(ERROR) << "Failed to get temporary directory.";
-+      return false;
-+    }
 +    if (!socket_dir_.Set(tmp_dir.Append("S"))) {
 +      LOG(ERROR) << "Failed to set socket directory.";
 +      return false;
@@ -197,14 +197,19 @@ index 4547eb8563e1af57aad991d9d1e2cf02c778380a..727333dd6abec99643e31bc77ed2cc8f
 +    // Create the socket file somewhere in /tmp which is usually mounted as a
 +    // normal filesystem. Some network filesystems (notably AFS) are screwy and
 +    // do not support Unix domain sockets.
-+    if (!socket_dir_.CreateUniqueTempDir()) {
++    // Prefer CreateUniqueTempDirUnderPath rather than CreateUniqueTempDir as
++    // the latter will calculate unique paths based on bundle ids which can
++    // increase the socket path length than what is allowed.
++    if (!socket_dir_.CreateUniqueTempDirUnderPath(tmp_dir)) {
 +      LOG(ERROR) << "Failed to create socket directory.";
 +      return false;
 +    }
-   }
- 
++  }
++
    // Check that the directory was created with the correct permissions.
-@@ -1046,10 +1100,13 @@ bool ProcessSingleton::Create() {
+   int dir_mode = 0;
+   CHECK(base::GetPosixFilePermissions(socket_dir_.GetPath(), &dir_mode) &&
+@@ -1046,10 +1104,13 @@ bool ProcessSingleton::Create() {
    if (listen(sock, 5) < 0)
      NOTREACHED() << "listen failed: " << base::safe_strerror(errno);