salimma / rpms / fish

Forked from rpms/fish 3 days ago
Clone

Blame 0001-parser-Stop-crashing-when-cwd-isn-t-readable.patch

Igor Raits dd0fb7
From b54f5ba56e6315028186af5d9e3b914dfae5a74f Mon Sep 17 00:00:00 2001
Igor Raits dd0fb7
From: Fabian Homborg <FHomborg@gmail.com>
Igor Raits dd0fb7
Date: Fri, 14 Feb 2020 17:18:27 +0100
Igor Raits dd0fb7
Subject: [PATCH 1/4] parser: Stop crashing when cwd isn't readable
Igor Raits dd0fb7
Igor Raits dd0fb7
Everything seems to be working, so instead of crashing just print an
Igor Raits dd0fb7
error and return.
Igor Raits dd0fb7
Igor Raits dd0fb7
Fixes #6597
Igor Raits dd0fb7
Igor Raits dd0fb7
(cherry picked from commit ceba851d44dea68b9e1b2b551e37fd6834767357)
Igor Raits dd0fb7
---
Igor Raits dd0fb7
 src/parser.cpp                        |  2 +-
Igor Raits dd0fb7
 tests/checks/init-unreadable-cwd.fish | 17 +++++++++++++++++
Igor Raits dd0fb7
 2 files changed, 18 insertions(+), 1 deletion(-)
Igor Raits dd0fb7
 create mode 100644 tests/checks/init-unreadable-cwd.fish
Igor Raits dd0fb7
Igor Raits dd0fb7
diff --git a/src/parser.cpp b/src/parser.cpp
Igor Raits dd0fb7
index 381b8ac06..1eae37392 100644
Igor Raits dd0fb7
--- a/src/parser.cpp
Igor Raits dd0fb7
+++ b/src/parser.cpp
Igor Raits dd0fb7
@@ -85,7 +85,7 @@ parser_t::parser_t(std::shared_ptr<env_stack_t> vars) : variables(std::move(vars
Igor Raits dd0fb7
     int cwd = open_cloexec(".", O_RDONLY);
Igor Raits dd0fb7
     if (cwd < 0) {
Igor Raits dd0fb7
         perror("Unable to open the current working directory");
Igor Raits dd0fb7
-        abort();
Igor Raits dd0fb7
+        return;
Igor Raits dd0fb7
     }
Igor Raits dd0fb7
     libdata().cwd_fd = std::make_shared<const autoclose_fd_t>(cwd);
Igor Raits dd0fb7
 }
Igor Raits dd0fb7
diff --git a/tests/checks/init-unreadable-cwd.fish b/tests/checks/init-unreadable-cwd.fish
Igor Raits dd0fb7
new file mode 100644
Igor Raits dd0fb7
index 000000000..fee220847
Igor Raits dd0fb7
--- /dev/null
Igor Raits dd0fb7
+++ b/tests/checks/init-unreadable-cwd.fish
Igor Raits dd0fb7
@@ -0,0 +1,17 @@
Igor Raits dd0fb7
+#RUN: %fish -C 'set -g fish %fish' %s
Igor Raits dd0fb7
+# Test that fish doesn't crash if cwd is unreadable at the start (#6597)
Igor Raits dd0fb7
+
Igor Raits dd0fb7
+set -l oldpwd $PWD
Igor Raits dd0fb7
+set -l tmpdir (mktemp -d)
Igor Raits dd0fb7
+
Igor Raits dd0fb7
+# $fish might be a relative path (e.g. "../test/root/bin/fish")
Igor Raits dd0fb7
+set -l fish (builtin realpath $fish)
Igor Raits dd0fb7
+cd $tmpdir
Igor Raits dd0fb7
+chmod 000 .
Igor Raits dd0fb7
+$fish -c 'echo Look Ma! No crashing!'
Igor Raits dd0fb7
+#CHECK: Look Ma! No crashing!
Igor Raits dd0fb7
+#CHECKERR: Unable to open the current working directory: Permission denied
Igor Raits dd0fb7
+
Igor Raits dd0fb7
+# Careful here, Solaris' rm tests if the directory is in $PWD, so we need to cd back
Igor Raits dd0fb7
+cd $oldpwd
Igor Raits dd0fb7
+rmdir $tmpdir
Igor Raits dd0fb7
-- 
Igor Raits dd0fb7
2.25.0
Igor Raits dd0fb7