about summary refs log tree commit diff
path: root/Src/Zle/compresult.c
diff options
context:
space:
mode:
authorAndrey Borzenkov <bor@users.sourceforge.net>2005-08-18 18:19:29 +0000
committerAndrey Borzenkov <bor@users.sourceforge.net>2005-08-18 18:19:29 +0000
commita6ebb7bfc3d1223860749a962703d56e7c81a098 (patch)
tree2d92ffc8c35072717bed9b424ee5828abc0a28c9 /Src/Zle/compresult.c
parentc26b8accb4b242991e4aae444a6799576a36783d (diff)
downloadzsh-a6ebb7bfc3d1223860749a962703d56e7c81a098.tar.gz
zsh-a6ebb7bfc3d1223860749a962703d56e7c81a098.tar.xz
zsh-a6ebb7bfc3d1223860749a962703d56e7c81a098.zip
21664: unmetafy ztat() argument
Diffstat (limited to 'Src/Zle/compresult.c')
-rw-r--r--Src/Zle/compresult.c28
1 files changed, 17 insertions, 11 deletions
diff --git a/Src/Zle/compresult.c b/Src/Zle/compresult.c
index e3b7d0523..d80a60ac1 100644
--- a/Src/Zle/compresult.c
+++ b/Src/Zle/compresult.c
@@ -849,27 +849,33 @@ do_ambiguous(void)
  * parameter says if we have to do lstat() or stat().  I think this   *
  * should instead be done by use of a general function to expand a    *
  * filename (stripping backslashes), combined with the actual         *
- * (l)stat().                                                         */
+ * (l)stat().                                                         *
+ * Make sure input is unmetafied                                      */
 
 /**/
 mod_export int
 ztat(char *nam, struct stat *buf, int ls)
 {
-    if (!(ls ? lstat(nam, buf) : stat(nam, buf)))
-	return 0;
-    else {
-	char *p;
-	VARARR(char, b, strlen(nam) + 1);
+    int ret;
+
+    nam = unmeta(nam);
+    if (!nam)
+	return -1;
 
-	for (p = b; *nam; nam++)
-	    if (*nam == '\\' && nam[1])
-		*p++ = *++nam;
+    if ((ret = ls ? lstat(nam, buf) : stat(nam, buf))) {
+	char *p, *q;
+
+	for (p = q = nam; *q; q++)
+	    if (*q == '\\' && q[1])
+		*p++ = *++q;
 	    else
-		*p++ = *nam;
+		*p++ = *q;
 	*p = '\0';
 	
-	return ls ? lstat(b, buf) : stat(b, buf);
+	ret = ls ? lstat(nam, buf) : stat(nam, buf);
     }
+
+    return ret;
 }
 
 /* Insert all matches in the command line. */