[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

user/965: ksh tab expansion doesn't quote shell metacharacters




>Number:         965
>Category:       user
>Synopsis:       ksh tab expansion doesn't quote shell metacharacters
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    bugs
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Thu Nov  4 23:20:01 MST 1999
>Last-Modified:
>Originator:     David Leonard
>Organization:
net
>Release:        2.6
>Environment:
	
	System      : OpenBSD 2.6
	Architecture: OpenBSD.i386
	Machine     : i386
>Description:
	When using ksh with tab-complete mode, and trying ot complete a
	filename with spaces in it, it completes fine, but the expanded word
	is not appropriately quoted.

	Same thing happens when using M-ESC in emacs mode.

>How-To-Repeat:
	% exec ksh -o vi -o vi-tabcomplete
	it2:linux$ ls
	Special Edition Using Linux Book.zip*
	it2:linux$ unzip -l Sp                                   
		[at this point I type tab, and then see:]
	it2:linux$ unzip -l Special Edition Using Linux Book.zip
	unzip:  cannot find Special, Special.zip or Special.ZIP.

>Fix:
	well this a partial attempt - can't finish it now.. network just died

Index: vi.c
===================================================================
RCS file: /occult/openbsd/cvs/src/bin/ksh/vi.c,v
retrieving revision 1.7
diff -u -r1.7 vi.c
--- vi.c	1999/07/14 13:37:24	1.7
+++ vi.c	1999/11/05 06:16:49
@@ -1998,6 +1998,8 @@
 	char **words;
 	char *match;
 	int match_len;
+	char *ematch;
+	int ematch_len, mpos;
 	int is_unique;
 	int is_command;
 
@@ -2070,7 +2072,17 @@
 	buf = save_edstate(es);
 	del_range(start, end);
 	es->cursor = start;
-	if (putbuf(match, match_len, 0) != 0)
+
+	/* escape match */
+	ematch = (char *)alloc(match_len * 2, APERM);
+	ematch_len = 0;
+	for (mpos = 0; mpos < match_len; mpos++) {
+		if (match[mpos] == ' ')	/* XXX needs proper meta check */
+			ematch[ematch_len++] = '\\'
+		ematch[ematch_len++] = match[mpos++];
+	}
+
+	if (putbuf(ematch, ematch_len, 0) != 0)
 		rval = -1;
 	else if (is_unique) {
 		/* If exact match, don't undo.  Allows directory completions
@@ -2083,6 +2095,7 @@
 			rval = putbuf(space, 1, 0);
 	}
 	x_free_words(nwords, words);
+	free(ematch);
 
 	modified = 1; hnum = hlast;
 	insert = INSERT;

>Audit-Trail:
>Unformatted: