From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Philipp Stephani Newsgroups: gmane.emacs.bugs Subject: bug#27871: 26.0.50; Bad handling of unmounted directory Date: Sat, 23 Sep 2017 11:33:13 +0000 Message-ID: References: <83a81lbswu.fsf@gnu.org> <87r2uxejo4.fsf@linux-m68k.org> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: multipart/alternative; boundary="001a113ca93a7c59090559d9b121" X-Trace: blaine.gmane.org 1506166449 2158 195.159.176.226 (23 Sep 2017 11:34:09 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Sat, 23 Sep 2017 11:34:09 +0000 (UTC) Cc: 27871@debbugs.gnu.org To: Andreas Schwab , Eli Zaretskii Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Sat Sep 23 13:34:04 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 1dvihA-0000DF-A6 for geb-bug-gnu-emacs@m.gmane.org; Sat, 23 Sep 2017 13:34:04 +0200 Original-Received: from localhost ([::1]:34505 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dvihH-0001Wc-KV for geb-bug-gnu-emacs@m.gmane.org; Sat, 23 Sep 2017 07:34:11 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:59336) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dvihC-0001WX-5e for bug-gnu-emacs@gnu.org; Sat, 23 Sep 2017 07:34:07 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dvih8-0000k5-7J for bug-gnu-emacs@gnu.org; Sat, 23 Sep 2017 07:34:06 -0400 Original-Received: from debbugs.gnu.org ([208.118.235.43]:44882) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1dvih8-0000k1-3p for bug-gnu-emacs@gnu.org; Sat, 23 Sep 2017 07:34:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1dvih7-0005r5-Tt for bug-gnu-emacs@gnu.org; Sat, 23 Sep 2017 07:34:01 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Philipp Stephani Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sat, 23 Sep 2017 11:34: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.150616641122470 (code B ref 27871); Sat, 23 Sep 2017 11:34:01 +0000 Original-Received: (at 27871) by debbugs.gnu.org; 23 Sep 2017 11:33:31 +0000 Original-Received: from localhost ([127.0.0.1]:53563 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dvigc-0005qM-Tl for submit@debbugs.gnu.org; Sat, 23 Sep 2017 07:33:31 -0400 Original-Received: from mail-oi0-f48.google.com ([209.85.218.48]:52613) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dvigb-0005q9-Mo for 27871@debbugs.gnu.org; Sat, 23 Sep 2017 07:33:30 -0400 Original-Received: by mail-oi0-f48.google.com with SMTP id p126so1639195oih.9 for <27871@debbugs.gnu.org>; Sat, 23 Sep 2017 04:33:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=aahdP2oC0xkICaJ8856OoOR9Bkd/t5mUql5ny69snPU=; b=ojsonWlCzPdgJi+ycXunwg5E2Nm/lWbPW3NSuqA0TIZKr/Py83vcrsAMysrG5F3PrX vBfh+8dxm6sDhy8A3qCIcYqmoxtjRFFYE1cAg+XWY3676FgzU0iLGNumdT282osdjO1c 3EAc//JzrqorchZcC18nhqZDgFOtL/v3VaQV3UgAwTKCzOmi6t1cIlfCoCIkCJ8G4Cja FNgMkqx57s0z/MaXWXkFettp2cHF9cX30mY2he0ijMWvF1yHrcGGfqo+nTnKN76Zpb9U kAJToB+SMPeOPhsKqef3N4SctjkGuPxjupedfj+u6jgrsKmgy41OjO12eucH4hoS2S62 W/0A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=aahdP2oC0xkICaJ8856OoOR9Bkd/t5mUql5ny69snPU=; b=aYtkUrgcVZPOuIQd6GutTNSETvzgjYdATj7TziStHU7e2KIIay/eLrHot/1fcEep6D KLVAc4P/ZDfeHfSCx2w4cEAApsnwmdeXxcCVUNP550ua27CfY6gxEnZf8vN0eyo5H8ix F9PBq1QiIgmv2h8qbqFciBpB/2dnOnkwqMwRvjucmvfnzqlnONjOLNQpHJKzPHqlFSKX aXpmGLq/HTY8Kqk82la3KVpPR3DCQOY9tXc8rBU5CI6i3/YcqXNMN740uNFo8QicoT2e PeqrzJpKsRVXP+HUEB3+D7V13jxkUcv7lBYE95AgTtAAhqb7i+qHEINidPDLxXY/NGqA K67A== X-Gm-Message-State: AHPjjUj3O7A12tVheY/+v/iu/mykXWSI/NcFFwmDKkm4a/GW/JZxPH3s V50fyU6QlQ+9ymKCIUf9htKSekhSiHg5Mqmf6No= X-Google-Smtp-Source: AOwi7QDWZz6b+R/MwaPUdk0ih2NqI4tNK14o1/ZGh0DiLu81Kbz/xPXomwmq2EkrPLZQJXieicMhxMiYYN7640jMU+k= X-Received: by 10.202.56.214 with SMTP id f205mr1340577oia.316.1506166404043; Sat, 23 Sep 2017 04:33:24 -0700 (PDT) In-Reply-To: <87r2uxejo4.fsf@linux-m68k.org> 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:137275 Archived-At: --001a113ca93a7c59090559d9b121 Content-Type: text/plain; charset="UTF-8" Andreas Schwab schrieb am Sa., 23. Sep. 2017 um 13:30 Uhr: > On Sep 23 2017, Eli Zaretskii wrote: > > >> +/* 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. */ > >> + const char *prefix = "(unreachable)"; > >> + size_t dir_len = strlen (dir); > >> + size_t prefix_len = strlen (prefix); > >> + if (dir_len >= prefix_len && strncmp (dir, prefix, prefix_len) == 0) > >> + { > >> + errno = ENOTCONN; > >> + return NULL; > > > > What if there's a directory called literally "(unreachable)SOMETHING"? > > An absolute file name cannot start with "(unreachable)". > > Yes, and getcwd and friends only return absolute filenames, and we only use $PWD if it's absolute, so anything except '/' or a drive letter can't be a prefix in the success case. I'll add a comment to that effect. --001a113ca93a7c59090559d9b121 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable


Andrea= s Schwab <schwab@linux-m68k.org= > schrieb am Sa., 23. Sep. 2017 um 13:30=C2=A0Uhr:
On Sep 23 2017, Eli Zaretskii <eliz@gnu.org> wrote:

>> +/* Return the current working directory.=C2=A0 The result should = be freed
>> +=C2=A0 =C2=A0with 'free'.=C2=A0 Return NULL on errors.=C2= =A0 */
>> +char *
>> +emacs_get_current_dir_name (void)
>> +{
>> +=C2=A0 char *dir =3D emacs_get_current_dir_name_1 ();
>> +=C2=A0 if (dir =3D=3D NULL)
>> +=C2=A0 =C2=A0 return NULL;
>> +=C2=A0 /* On Linux, getcwd and get_current_dir_name return a stri= ng
>> +=C2=A0 =C2=A0 =C2=A0starting with "(unreachable)" if th= e current directory doesn't
>> +=C2=A0 =C2=A0 =C2=A0exist, e.g. because it was unmounted.=C2=A0 T= reat that as an error.
>> +=C2=A0 =C2=A0 =C2=A0See https://debbu= gs.gnu.org/cgi/bugreport.cgi?bug=3D27871.=C2=A0 */
>> +=C2=A0 const char *prefix =3D "(unreachable)";
>> +=C2=A0 size_t dir_len =3D strlen (dir);
>> +=C2=A0 size_t prefix_len =3D strlen (prefix);
>> +=C2=A0 if (dir_len >=3D prefix_len && strncmp (dir, pr= efix, prefix_len) =3D=3D 0)
>> +=C2=A0 =C2=A0 {
>> +=C2=A0 =C2=A0 =C2=A0 errno =3D ENOTCONN;
>> +=C2=A0 =C2=A0 =C2=A0 return NULL;
>
> What if there's a directory called literally "(unreachable)SO= METHING"?

An absolute file name cannot start with "(unreachable)".


Yes, and getcwd and friends only retur= n absolute filenames, and we only use $PWD if it's absolute, so anythin= g except '/' or a drive letter can't be a prefix in the success= case. I'll add a comment to that effect.=C2=A0
--001a113ca93a7c59090559d9b121--