[prev in list] [next in list] [prev in thread] [next in thread] 

List:       openbsd-tech
Subject:    ksh globbing vs. trailing backslash [patch]
From:       David Higgs <higgsd () gmail ! com>
Date:       2011-02-26 3:06:34
Message-ID: 03EB7D03-0969-4FB1-B576-D972A8D98F9F () gmail ! com
[Download RAW message or body]

Long time user, first time patch submission.  I can send this again after tree
lock, but feedback is welcome in the meantime.

I started trying to fix PR 6006 and felt like there was progress being made
for a while.  I was pretty sure that x_file_glob function shouldn't have
stripped backslashes before lexing, which caused the unescaped backtick to
throw the error.  However, the code that checked for globbing failure would
then have to be adjusted, and I couldn't find logic to consistently predict
what expand() would return on such failure.  Getting that wrong caused tab
completion to incorrectly escape the input buffer.

Long story short I didn't fix the PR but found a minor nit that seemed safe to
fix: don't allow add_glob to process strings with a trailing backslash.

# patched code sends a bell instead of displaying "matches"
# unpatched code displays as below
[vm@vm obj]$ cd c_\<TAB>
c_ksh.o      c_sh.o       c_test.o     c_ulimit.o

Thanks.

--david

Index: edit.c
===================================================================
RCS file: /cvs/src/bin/ksh/edit.c,v
retrieving revision 1.34
diff -u -r1.34 edit.c
--- edit.c	20 May 2010 01:13:07 -0000	1.34
+++ edit.c	26 Feb 2011 01:34:36 -0000
@@ -355,7 +355,10 @@
 	if (slen < 0)
 		return 0;

-	toglob = add_glob(str, slen);
+	if ((toglob = add_glob(str, slen)) == NULL) {
+		*wordsp = NULL;
+		return 0;
+	}

 	/* remove all escaping backward slashes */
 	escaping = 0;
@@ -455,7 +458,10 @@
 	if (slen < 0)
 		return 0;

-	toglob = add_glob(str, slen);
+	if ((toglob = add_glob(str, slen)) == NULL) {
+		*wordsp = NULL;
+		return 0;
+	}

 	/* Convert "foo*" (toglob) to a pattern for future use */
 	pat = evalstr(toglob, DOPAT|DOTILDE);
@@ -646,6 +652,10 @@
 	for (s = toglob; *s; s++) {
 		if (*s == '\\' && s[1])
 			s++;
+		else if (*s == '\\' && !s[1]) {
+			afree(toglob, ATEMP);
+			return NULL;
+		}
 		else if (*s == '*' || *s == '[' || *s == '?' || *s == '$' ||
 		    (s[1] == '(' /*)*/ && strchr("+@!", *s)))
 			break;

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic