From a6ebb7bfc3d1223860749a962703d56e7c81a098 Mon Sep 17 00:00:00 2001 From: Andrey Borzenkov Date: Thu, 18 Aug 2005 18:19:29 +0000 Subject: 21664: unmetafy ztat() argument --- Src/Zle/compresult.c | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) (limited to 'Src/Zle/compresult.c') 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. */ -- cgit 1.4.1