GNU bug report logs - #27871
26.0.50; Bad handling of unmounted directory

Previous Next

Package: emacs;

Reported by: Philipp <p.stephani2 <at> gmail.com>

Date: Sat, 29 Jul 2017 21:08:02 UTC

Severity: minor

Found in version 26.0.50

Done: Paul Eggert <eggert <at> cs.ucla.edu>

Bug is archived. No further changes may be made.

Full log


View this message in rfc822 format

From: Philipp Stephani <p.stephani2 <at> gmail.com>
To: emacs-devel <at> gnu.org, 27871 <at> debbugs.gnu.org
Cc: Philipp Stephani <phst <at> google.com>
Subject: bug#27871: [PATCH] Treat unreachable current directory as error
Date: Sat, 30 Sep 2017 20:50:06 +0200
Linux prefixes an unreachable (e.g. unmounted) current directory with
the special string "(unreachable)", cf. Bug#27871.  Treat such
directories as error because they wouldn't work anyway.

* src/sysdep.c (emacs_get_current_dir_name_1): Renamed from
emacs_get_current_dir_name.
(emacs_get_current_dir_name): Check for prefix "(unreachable)".
---
 src/sysdep.c | 27 +++++++++++++++++++++++----
 1 file changed, 23 insertions(+), 4 deletions(-)

diff --git a/src/sysdep.c b/src/sysdep.c
index 1e6e0d011b..efc0396c93 100644
--- a/src/sysdep.c
+++ b/src/sysdep.c
@@ -220,10 +220,8 @@ init_standard_fds (void)
   force_open (STDERR_FILENO, O_RDONLY);
 }
 
-/* Return the current working directory.  The result should be freed
-   with 'free'.  Return NULL on errors.  */
-char *
-emacs_get_current_dir_name (void)
+static char *
+emacs_get_current_dir_name_1 (void)
 {
 # if HAVE_GET_CURRENT_DIR_NAME && !BROKEN_GET_CURRENT_DIR_NAME
 #  ifdef HYBRID_MALLOC
@@ -283,6 +281,27 @@ emacs_get_current_dir_name (void)
   return buf;
 }
 
+/* Return the current working directory.  The result should be freed
+   with 'free'.  Return NULL on errors.  */
+char *
+emacs_get_current_dir_name (void)
+{
+  char *dir = emacs_get_current_dir_name_1 ();
+  if (dir == NULL)
+    return NULL;
+  /* On Linux, getcwd and get_current_dir_name return a string
+     starting with "(unreachable)" if the current directory doesn't
+     exist, e.g. because it was unmounted.  Treat that as an error.
+     See https://debbugs.gnu.org/cgi/bugreport.cgi?bug=27871.  */
+  if (!file_name_absolute_p (dir))
+    {
+      free (dir);
+      errno = ENOTCONN;
+      return NULL;
+    }
+  return dir;
+}
+
 
 /* Discard pending input on all input descriptors.  */
 
-- 
2.14.1





This bug report was last modified 7 years and 233 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.