From 4094bd89cf51f2239b7e61b3d5745da88760a68d Mon Sep 17 00:00:00 2001 From: Christian Blichmann Date: Thu, 19 Sep 2024 04:58:50 -0700 Subject: [PATCH] Actually better error message for `mount()` and `ENOENT` The previous change assumed that we could mount over a dangling symlink, which is true for the `mount` command-line tool, but not actually for the `mount()` syscall. Also removed the odd `%s%s%s%s` string format in the message in favor of an easier to read if-else. PiperOrigin-RevId: 676366941 Change-Id: Ib0bab7e18adadbb4dda79bbaa404f44bc6141cdb --- sandboxed_api/sandbox2/mounts.cc | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/sandboxed_api/sandbox2/mounts.cc b/sandboxed_api/sandbox2/mounts.cc index 5ab85400..603eb3b0 100644 --- a/sandboxed_api/sandbox2/mounts.cc +++ b/sandboxed_api/sandbox2/mounts.cc @@ -641,19 +641,21 @@ void MountWithDefaults(const std::string& source, const std::string& target, // File does not exist (anymore). This may be the case when trying to // gather stack-traces on SAPI crashes. The sandboxee application is a // memfd file that is not existing anymore. - // Check which file/dir of the call is actually missing. Do not follow - // symlinks here as it's valid to "mount over" a dangling symlink. + // Check which file/dir of the call is actually missing. bool have_source = - file_util::fileops::Exists(source, /*fully_resolve=*/false); + file_util::fileops::Exists(source, /*fully_resolve=*/true); bool have_target = - file_util::fileops::Exists(target, /*fully_resolve=*/false); - SAPI_RAW_LOG(WARNING, - "Could not mount %s (source) to %s (target): %s%s%s%s exist", - source.c_str(), target.c_str(), - have_source || have_target ? "" : "neither ", - have_source ? "" : "source", - have_source || have_target ? "" : " nor ", - have_target ? "" : "target"); + file_util::fileops::Exists(target, /*fully_resolve=*/true); + const char* detail = "unknown error, source and target exist"; + if (!have_source && !have_target) { + detail = "neither source nor target exist"; + } else if (!have_source) { + detail = "source does not exist"; + } else if (!have_target) { + detail = "target does not exist"; + } + SAPI_RAW_LOG(WARNING, "Could not mount %s (source) to %s (target): %s", + source.c_str(), target.c_str(), detail); return; } SAPI_RAW_PLOG(FATAL, "mounting %s to %s failed (flags=%s)", source, target,