NetBSD Problem Report #22846

Received: (qmail 8815 invoked by uid 605); 18 Sep 2003 15:54:49 -0000
Message-Id: <20030918155442.8C54E24B@sun.local>
Date: Thu, 18 Sep 2003 17:54:42 +0200 (CEST)
From: jmmv@menta.net
Sender: gnats-bugs-owner@NetBSD.org
Reply-To: jmmv@menta.net
To: gnats-bugs@gnats.netbsd.org
Subject: ksh does not complete names with square brackets properly
X-Send-Pr-Version: 3.95

>Number:         22846
>Category:       bin
>Synopsis:       ksh does not complete names with square brackets properly
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    bin-bug-people
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Thu Sep 18 15:55:00 +0000 2003
>Closed-Date:    
>Last-Modified:  Tue Nov 24 16:05:02 +0000 2009
>Originator:     Julio M. Merino Vidal
>Release:        NetBSD 1.6ZC
>Organization:
Julio M. Merino Vidal <jmmv@menta.net>
The NetBSD Project - http://www.NetBSD.org/
>Environment:


System: NetBSD dawn.local 1.6ZC NetBSD 1.6ZC (DAWN) #2: Wed Sep 17 12:06:13 CEST 2003 jmmv@dawn.local:/home/NetBSD/obj/home/NetBSD/src/sys/arch/i386/compile/DAWN i386
Architecture: i386
Machine: i386
>Description:
	ksh does not complete names with square brackets in them properly.
	This only happens when two files in the same directory have "similar"
	names, that is, they share a prefix which can be completed in two
	different ways.
>How-To-Repeat:
	$ touch a.[b].1
	$ touch a.[b].2
	$ ls aTAB
	(see how it completes the name until a.[b]. and stops there).
	$ ls a.\[b\]TAB
	(this fails too).
	$ rm a.\[b\].2
	$ ls aTAB
	(and see how it completes the name properly).
>Fix:
	I tried adding [] to the list of characters to be escaped, and while
	ksh will add the backslash, completion will fail.
>Release-Note:
>Audit-Trail:

From: fredb@immanent.net (Frederick Bruckman)
To: jmmv@menta.net
Cc: fredb@netbsd.org, gnats-bugs@gnats.netbsd.org
Subject: Re: bin/22846: ksh does not complete names with square brackets properly
Date: Thu, 18 Sep 2003 20:13:01 -0500 (CDT)

 In article <20030918155442.8C54E24B@sun.local>,
 	jmmv@menta.net writes:
 > 
 >>Number:         22846
 >>Category:       bin
 >>Synopsis:       ksh does not complete names with square brackets properly

 For what it's worth, it's an old bug:

     http://www.cs.mun.ca/~michael/pdksh/BUG-REPORTS

 It's the third one down. I find it also occurs with filenames with
 parenthesis (NetBSD 1.6.1/pdksh 5.2.14).


 Frederick
State-Changed-From-To: open->closed
State-Changed-By: dsl@netbsd.org
State-Changed-When: Mon, 18 Sep 2006 06:30:59 +0000
State-Changed-Why:
This seems to work correctly now.


From: Christian Biere <christianbiere@gmx.de>
To: gnats-bugs@NetBSD.org
Cc: 
Subject: Re: bin/22846
Date: Sun, 8 Oct 2006 05:09:23 +0200

 This bug is actually not fixed. ksh has still problems with tab-completion
 if there's a brackets '[' in the filename.

 $ touch '[]'
 $ ls \[<tab>

 Hitting <tab> doesn't cause any completion. The same applies without a
 leading backslash. Appending './' or a single-quote doesn't help either.
 Further, consider the following:

 $ touch 'yadda[a-z]'
 $ ls yadda<tab>
 ... gains
 $ ls yadda[a-z]

 Note that the brackets are not escaped. If a file matching the pattern
 exists, for example "yaddab", the completion stops at the opening bracket
 and then blocks as in the first case.

 This is vulnerable to a race-condition. If yaddab is created after
 tab-completion but before the command is executed, the command will use
 yaddab and not 'yadda[a-z]'. The same applies to '?' which is not escaped
 either when using tab completion.

 ksh does the right thing for '{', '}', '(', ')' and '*' but not '[', ']'
 and '?'.

 -- 
 Christian

From: Christian Biere <christianbiere@gmx.de>
To: gnats-bugs@NetBSD.org
Cc: 
Subject: Re: bin/22846
Date: Sun, 8 Oct 2006 05:34:41 +0200

 Christian Biere wrote:
 > The following reply was made to PR bin/22846; it has been noted by GNATS.
 >  $ touch 'yadda[a-z]'
 >  $ ls yadda<tab>
 >  ... gains
 >  $ ls yadda[a-z]

 The following patch should fix this i.e., adds quoting for "[]?". Maybe
 there's another shell meta character that should be escaped as well.

 This doesn't fix the original issue regarding non-working tab completion
 though.

 Index: bin/ksh/edit.c
 ===================================================================
 RCS file: /cvsroot/src/bin/ksh/edit.c,v
 retrieving revision 1.20
 diff -u -r1.20 edit.c
 --- bin/ksh/edit.c	14 May 2006 01:09:03 -0000	1.20
 +++ bin/ksh/edit.c	8 Oct 2006 03:31:40 -0000
 @@ -1072,7 +1072,7 @@
  	int rval=0;

  	for (add = 0, wlen = len; wlen - add > 0; add++) {
 -		if (strchr("\\$(){}*&;#|<>\"'`", s[add]) || strchr(ifs, s[add])) {
 +		if (strchr("\\$(){}[]?*&;#|<>\"'`", s[add]) || strchr(ifs, s[add])) {
  			if (putbuf_func(s, add) != 0) {
  				rval = -1;
  				break;

State-Changed-From-To: closed->open
State-Changed-By: wiz@netbsd.org
State-Changed-When: Mon, 09 Oct 2006 17:54:45 +0000
State-Changed-Why:
Still not fixed completely (Christian Biere sent a patch).


From: Christian Biere <christianbiere@gmx.de>
To: gnats-bugs@NetBSD.org
Cc: 
Subject: Re: bin/22846
Date: Wed, 11 Oct 2006 08:08:05 +0200

 Christian Biere wrote:
 > There's a way to convince ksh to expand filenames with brackets:
 > 
 > $ touch '[foo]'
 > $ touch '[bar]'
 > $ ls \[\[]f<tab>

 The reason this works is that x_file_glob() strips all backslashes,
 thus glob() will see [[]f whis is a literal '[f' as desired.

 The following partial patch fixes cases like the above but not
 those which require multiple tab completions:

  $ touch '[foo].bak'
  $ ls [f<tab>	# expands too \[foo\]
  $ ls \[foo\].<tab> # does not expand

 Obviously, due to the internal stripped backslashes [foo].<tab>
 won't expand because there is no matching file. However, even
 if the backslashes are kept, yylex() does record these as
 literal characters instead of marking the following character
 as quoted.

 The partial patch simply adds a check to see whether there
 is an unquoted '[' is followed by an unquoted ']'. If not,
 the '[' does not initiate a glob pattern.

 --- bin/ksh/edit.c	2006-10-08 05:29:36.000000000 +0200
 +++ bin/ksh/edit.c	2006-10-11 07:49:55.000000000 +0200
 @@ -880,7 +880,7 @@
  	for (s = toglob; *s; s++) {
  		if (*s == '\\' && s[1])
  			s++;
 -		else if (*s == '*' || *s == '[' || *s == '?' || *s == '$'
 +		else if (*s == '*' || *s == '?' || *s == '$'
  			 || (s[1] == '(' /*)*/ && strchr("*+?@!", *s)))
  			break;
  		else if (ISDIRSEP(*s))
 --- bin/ksh/eval.c	2006-05-23 16:45:10.000000000 +0200
 +++ bin/ksh/eval.c	2006-10-11 06:48:51.000000000 +0200
 @@ -605,6 +605,21 @@
  			if (!quote)
  				switch (c) {
  				  case '[':
 +					{
 +						const char *p = sp;
 +						bool_t special = FALSE;
 +						while (*p != EOS) {
 +							if (p[0] == CHAR &&
 +								p[1] == ']') {
 +								special = TRUE;
 +								break;
 +							}
 +								
 +							p += 2;
 +						}
 +						if (!special)
 +							break;
 +					}
  				  case NOT:
  				  case '-':
  				  case ']':

From: Christian Biere <cbiere@netbsd.org>
To: gnats-bugs@NetBSD.org
Cc: 
Subject: PR/22846 CVS commit: src/bin/ksh
Date: Sun, 28 Jan 2007 20:20:26 +0000 (UTC)

 Module Name:	src
 Committed By:	cbiere
 Date:		Sun Jan 28 20:20:25 UTC 2007

 Modified Files:
 	src/bin/ksh: edit.c eval.c

 Log Message:
  * Escape '?', '[', ']' like other meta characters.
  * Partial fix for completion when '[' is in the way.
  * Addresses PR bin/22846.


 To generate a diff of this commit:
 cvs rdiff -r1.20 -r1.21 src/bin/ksh/edit.c
 cvs rdiff -r1.8 -r1.9 src/bin/ksh/eval.c

 Please note that diffs are not public domain; they are subject to the
 copyright notices on the relevant files.

From: Sean Boudreau <seanb@qnx.com>
To: gnats-bugs@NetBSD.org
Cc: 
Subject: Re: bin/22846
Date: Sun, 15 Nov 2009 19:05:30 -0500

 The previous commit breaks the following scenario

 # cat ./scr
 onexit()
 {
 	rm /tmp/ksh_testfile[12]
 }

 bomb()
 {
     echo $1
     exit 1
 }

 trap onexit EXIT
 touch /tmp/ksh_testfile1 /tmp/ksh_testfile2 || bomb "couldn't create  /tmp/ksh_testfile\*"

 FOO="/tmp/ksh_testfile[1-2]"
 RES=$(echo $FOO)
 EXPECT="/tmp/ksh_testfile1 /tmp/ksh_testfile2"
 if [ "${RES}" != "${EXPECT}" ]; then
 	bomb "got: \"${RES}\" expected \"${EXPECT}\""
 else
 	echo "Success"
 fi
 # ksh ./scr
 got: "/tmp/ksh_testfile[1-2]" expected "/tmp/ksh_testfile1 /tmp/ksh_testfile2"

From: Sean Boudreau <seanb@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc: 
Subject: PR/22846 CVS commit: src/bin/ksh
Date: Tue, 24 Nov 2009 16:00:42 +0000

 Module Name:	src
 Committed By:	seanb
 Date:		Tue Nov 24 16:00:42 UTC 2009

 Modified Files:
 	src/bin/ksh: edit.c eval.c

 Log Message:
 Back out fix for PR 22846 as it has issues.  See PR 22846 for details.


 To generate a diff of this commit:
 cvs rdiff -u -r1.22 -r1.23 src/bin/ksh/edit.c
 cvs rdiff -u -r1.11 -r1.12 src/bin/ksh/eval.c

 Please note that diffs are not public domain; they are subject to the
 copyright notices on the relevant files.

>Unformatted:

NetBSD Home
NetBSD PR Database Search

(Contact us) $NetBSD: query-full-pr,v 1.39 2013/11/01 18:47:49 spz Exp $
$NetBSD: gnats_config.sh,v 1.8 2006/05/07 09:23:38 tsutsui Exp $
Copyright © 1994-2007 The NetBSD Foundation, Inc. ALL RIGHTS RESERVED.