From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Paul Eggert Newsgroups: gmane.emacs.bugs Subject: bug#27871: [PATCH] Treat unreachable current directory as error Date: Sat, 7 Oct 2017 23:04:54 -0700 Organization: UCLA Computer Science Department Message-ID: <9b7b9905-dc97-feb4-9569-27372b1c6b5d@cs.ucla.edu> References: <20170930185006.54096-1-phst@google.com> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="------------267EEDB52C8C4A56A73B1C57" X-Trace: blaine.gmane.org 1507442771 4811 195.159.176.226 (8 Oct 2017 06:06:11 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Sun, 8 Oct 2017 06:06:11 +0000 (UTC) User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.3.0 Cc: Philipp Stephani To: Philipp Stephani , 27871@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Sun Oct 08 08:06:06 2017 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1e14iy-0000Nv-KL for geb-bug-gnu-emacs@m.gmane.org; Sun, 08 Oct 2017 08:06:04 +0200 Original-Received: from localhost ([::1]:52612 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e14j6-0007yz-5a for geb-bug-gnu-emacs@m.gmane.org; Sun, 08 Oct 2017 02:06:12 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:44899) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e14iz-0007yr-HJ for bug-gnu-emacs@gnu.org; Sun, 08 Oct 2017 02:06:06 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1e14iw-00034a-Ad for bug-gnu-emacs@gnu.org; Sun, 08 Oct 2017 02:06:05 -0400 Original-Received: from debbugs.gnu.org ([208.118.235.43]:46740) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1e14iw-00034W-63 for bug-gnu-emacs@gnu.org; Sun, 08 Oct 2017 02:06:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1e14iv-00063C-UF for bug-gnu-emacs@gnu.org; Sun, 08 Oct 2017 02:06:01 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Paul Eggert Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sun, 08 Oct 2017 06:06:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 27871 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: Original-Received: via spool by 27871-submit@debbugs.gnu.org id=B27871.150744270423192 (code B ref 27871); Sun, 08 Oct 2017 06:06:01 +0000 Original-Received: (at 27871) by debbugs.gnu.org; 8 Oct 2017 06:05:04 +0000 Original-Received: from localhost ([127.0.0.1]:55421 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1e14i0-000620-1v for submit@debbugs.gnu.org; Sun, 08 Oct 2017 02:05:04 -0400 Original-Received: from zimbra.cs.ucla.edu ([131.179.128.68]:48092) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1e14hy-00061M-Fc for 27871@debbugs.gnu.org; Sun, 08 Oct 2017 02:05:03 -0400 Original-Received: from localhost (localhost [127.0.0.1]) by zimbra.cs.ucla.edu (Postfix) with ESMTP id 8730E160D38; Sat, 7 Oct 2017 23:04:55 -0700 (PDT) Original-Received: from zimbra.cs.ucla.edu ([127.0.0.1]) by localhost (zimbra.cs.ucla.edu [127.0.0.1]) (amavisd-new, port 10032) with ESMTP id 7KRQ-6M5pBnq; Sat, 7 Oct 2017 23:04:54 -0700 (PDT) Original-Received: from localhost (localhost [127.0.0.1]) by zimbra.cs.ucla.edu (Postfix) with ESMTP id 9DF7F160E42; Sat, 7 Oct 2017 23:04:54 -0700 (PDT) X-Virus-Scanned: amavisd-new at zimbra.cs.ucla.edu Original-Received: from zimbra.cs.ucla.edu ([127.0.0.1]) by localhost (zimbra.cs.ucla.edu [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id Xc6z4n37Vy93; Sat, 7 Oct 2017 23:04:54 -0700 (PDT) Original-Received: from [192.168.1.9] (unknown [47.154.18.85]) by zimbra.cs.ucla.edu (Postfix) with ESMTPSA id 741AB160D38; Sat, 7 Oct 2017 23:04:54 -0700 (PDT) In-Reply-To: Content-Language: en-US X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 208.118.235.43 X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.org gmane.emacs.bugs:138065 Archived-At: This is a multi-part message in MIME format. --------------267EEDB52C8C4A56A73B1C57 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: quoted-printable Philipp Stephani wrote: > All of the current directory functions exhibit this behavior, including > getwd and getcwd, so you need to make sure they are also covered. Thanks for letting us know. I installed the 2nd attached patch, which add= resses=20 this by making the patch behave more like what you originally proposed, w= hile=20 still avoiding the need to use file_name_absolute_p (which is about Emacs= file=20 names, not OS names). Also, I noticed a related memory leak and fixed tha= t by=20 installing the 1st attached patch. --------------267EEDB52C8C4A56A73B1C57 Content-Type: text/x-patch; name="0001-src-xsmfns.c-x_session_initialize-Fix-memory-leak.patch" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename*0="0001-src-xsmfns.c-x_session_initialize-Fix-memory-leak.patch" =46rom 2202952b8307f3a6407820280e94e4d979b7a122 Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Sat, 7 Oct 2017 22:48:49 -0700 Subject: [PATCH 1/2] * src/xsmfns.c (x_session_initialize): Fix memory le= ak. --- src/xsmfns.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/xsmfns.c b/src/xsmfns.c index 2cb4f3e..fb0d01b 100644 --- a/src/xsmfns.c +++ b/src/xsmfns.c @@ -401,12 +401,14 @@ x_session_initialize (struct x_display_info *dpyinf= o) ptrdiff_t name_len =3D 0; =20 /* libSM seems to crash if pwd is missing - see bug#18851. */ - if (! emacs_get_current_dir_name ()) + char *pwd =3D emacs_get_current_dir_name (); + if (!pwd) { fprintf (stderr, "Disabling session management due to pwd error: %= s\n", emacs_strerror (errno)); return; } + xfree (pwd); =20 ice_fd =3D -1; doing_interact =3D false; --=20 2.7.4 --------------267EEDB52C8C4A56A73B1C57 Content-Type: text/x-patch; name="0002-Improve-test-for-unreachable-dirs.patch" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="0002-Improve-test-for-unreachable-dirs.patch" =46rom 7c2c117c91eeef5e7bd70c98cc7e201007016b1e Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Sat, 7 Oct 2017 22:56:29 -0700 Subject: [PATCH 2/2] Improve test for unreachable dirs * src/sysdep.c (get_current_dir_name_or_unreachable): New function, with most of the old contents of emacs_get_current_dir_name. (emacs_get_current_dir_name): Use it. Use a simpler test for unreachable directory strings, and also apply it to getcwd etc. (Bug#27871) --- src/sysdep.c | 39 ++++++++++++++++++++++++++------------- 1 file changed, 26 insertions(+), 13 deletions(-) diff --git a/src/sysdep.c b/src/sysdep.c index 8291a60..c348492 100644 --- a/src/sysdep.c +++ b/src/sysdep.c @@ -221,9 +221,12 @@ init_standard_fds (void) } =20 /* Return the current working directory. The result should be freed - with 'free'. Return NULL on errors. */ -char * -emacs_get_current_dir_name (void) + with 'free'. Return NULL (setting errno) on errors. If the + current directory is unreachable, return either NULL or a string + beginning with '('. */ + +static char * +get_current_dir_name_or_unreachable (void) { # if HAVE_GET_CURRENT_DIR_NAME && !BROKEN_GET_CURRENT_DIR_NAME # ifdef HYBRID_MALLOC @@ -233,16 +236,9 @@ emacs_get_current_dir_name (void) # endif if (use_libc) { - /* GNU/Linux get_current_dir_name can return a string starting - with "(unreachable)" (Bug#27871). */ - char *wd =3D get_current_dir_name (); - if (wd && ! (IS_DIRECTORY_SEP (*wd) || (*wd && IS_DEVICE_SEP (wd[1= ])))) - { - free (wd); - errno =3D ENOENT; - return NULL; - } - return wd; + /* For an unreachable directory, this returns a string that starts= + with "(unreachable)"; see Bug#27871. */ + return get_current_dir_name (); } # endif =20 @@ -294,6 +290,23 @@ emacs_get_current_dir_name (void) return buf; } =20 +/* Return the current working directory. The result should be freed + with 'free'. Return NULL (setting errno) on errors; an unreachable + directory (e.g., its name starts with '(') counts as an error. */ + +char * +emacs_get_current_dir_name (void) +{ + char *dir =3D get_current_dir_name_or_unreachable (); + if (dir && *dir =3D=3D '(') + { + free (dir); + errno =3D ENOENT; + return NULL; + } + return dir; +} + =0C /* Discard pending input on all input descriptors. */ =20 --=20 2.7.4 --------------267EEDB52C8C4A56A73B1C57--