about summary refs log tree commit diff
path: root/Src/Zle/computil.c
diff options
context:
space:
mode:
authorDaniel Shahaf <d.s@daniel.shahaf.name>2016-09-04 18:26:32 +0000
committerDaniel Shahaf <d.s@daniel.shahaf.name>2016-09-06 23:48:10 +0000
commit73c0e8d4e679ed681acc4883234324c7676cc676 (patch)
treea9f037be06e051ee5bc4f68ecbd57e70f46ad8aa /Src/Zle/computil.c
parent831a336c494b55641b4ba2c8bb89a8acda2709f8 (diff)
downloadzsh-73c0e8d4e679ed681acc4883234324c7676cc676.tar.gz
zsh-73c0e8d4e679ed681acc4883234324c7676cc676.tar.xz
zsh-73c0e8d4e679ed681acc4883234324c7676cc676.zip
39173: _arguments: Escape colons and backslashes in $opt_args unambiguously.
Diffstat (limited to 'Src/Zle/computil.c')
-rw-r--r--Src/Zle/computil.c12
1 files changed, 9 insertions, 3 deletions
diff --git a/Src/Zle/computil.c b/Src/Zle/computil.c
index ecfa2bc34..1c90a543a 100644
--- a/Src/Zle/computil.c
+++ b/Src/Zle/computil.c
@@ -2310,7 +2310,10 @@ ca_parse_line(Cadef d, int multi, int first)
     return 0;
 }
 
-/* Build a colon-list from a list. */
+/* Build a colon-list from a list.
+ *
+ * This is only used to populate values of $opt_args.
+ */
 
 static char *
 ca_colonlist(LinkList l)
@@ -2320,16 +2323,19 @@ ca_colonlist(LinkList l)
 	int len = 0;
 	char *p, *ret, *q;
 
+	/* Compute the length to be allocated. */
 	for (n = firstnode(l); n; incnode(n)) {
 	    len++;
 	    for (p = (char *) getdata(n); *p; p++)
-		len += (*p == ':' ? 2 : 1);
+		len += (*p == ':' || *p == '\\') ? 2 : 1;
 	}
 	ret = q = (char *) zalloc(len);
 
+	/* Join L into RET, joining with colons and escaping colons and
+	 * backslashes. */
 	for (n = firstnode(l); n;) {
 	    for (p = (char *) getdata(n); *p; p++) {
-		if (*p == ':')
+		if (*p == ':' || *p == '\\')
 		    *q++ = '\\';
 		*q++ = *p;
 	    }