1
0
Fork 0
mirror of git://git.code.sf.net/p/zsh/code synced 2025-09-24 05:11:08 +02:00

21664: unmetafy ztat() argument

This commit is contained in:
Andrey Borzenkov 2005-08-18 18:19:29 +00:00
parent c26b8accb4
commit a6ebb7bfc3
3 changed files with 22 additions and 20 deletions

View file

@ -3,6 +3,9 @@
* 21663: Src/Zle/complete.c: check for string overflow * 21663: Src/Zle/complete.c: check for string overflow
in do_comp_vars() in do_comp_vars()
* 21664: Src/Zle/compcore.c, Src/Zle/compresult.c: unmetafy
argument in ztat() before calling (l)stat
2005-08-18 Peter Stephenson <pws@csr.com> 2005-08-18 Peter Stephenson <pws@csr.com>
* unposted: Doc/Zsh/contrib.yo, Functions/Zle/insert-unicode-char: * unposted: Doc/Zsh/contrib.yo, Functions/Zle/insert-unicode-char:

View file

@ -2471,24 +2471,17 @@ add_match_data(int alt, char *str, char *orig, Cline line,
cm->modec = '\0'; cm->modec = '\0';
if ((flags & CMF_FILE) && orig[0] && orig[strlen(orig) - 1] != '/') { if ((flags & CMF_FILE) && orig[0] && orig[strlen(orig) - 1] != '/') {
struct stat buf; struct stat buf;
char *pb, *blah; char *pb;
int blahl;
pb = (char *) zhalloc((cm->prpre ? strlen(cm->prpre) : 0) + pb = (char *) zhalloc((cm->prpre ? strlen(cm->prpre) : 0) +
3 + strlen(orig)); 3 + strlen(orig));
sprintf(pb, "%s%s", (cm->prpre ? cm->prpre : "./"), orig); sprintf(pb, "%s%s", (cm->prpre ? cm->prpre : "./"), orig);
blah = ztrdup(pb); if (!ztat(pb, &buf, 1)) {
unmetafy(blah, &blahl);
if (!ztat(blah, &buf, 1)) {
cm->mode = buf.st_mode; cm->mode = buf.st_mode;
if ((cm->modec = file_type(buf.st_mode)) == ' ') if ((cm->modec = file_type(buf.st_mode)) == ' ')
cm->modec = '\0'; cm->modec = '\0';
} }
free(blah);
} }
if ((*compqstack == '\\' && compqstack[1]) || if ((*compqstack == '\\' && compqstack[1]) ||
(autoq && *compqstack && compqstack[1] == '\\')) (autoq && *compqstack && compqstack[1] == '\\'))

View file

@ -849,27 +849,33 @@ do_ambiguous(void)
* parameter says if we have to do lstat() or stat(). I think this * * 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 * * should instead be done by use of a general function to expand a *
* filename (stripping backslashes), combined with the actual * * filename (stripping backslashes), combined with the actual *
* (l)stat(). */ * (l)stat(). *
* Make sure input is unmetafied */
/**/ /**/
mod_export int mod_export int
ztat(char *nam, struct stat *buf, int ls) ztat(char *nam, struct stat *buf, int ls)
{ {
if (!(ls ? lstat(nam, buf) : stat(nam, buf))) int ret;
return 0;
else {
char *p;
VARARR(char, b, strlen(nam) + 1);
for (p = b; *nam; nam++) nam = unmeta(nam);
if (*nam == '\\' && nam[1]) if (!nam)
*p++ = *++nam; return -1;
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 else
*p++ = *nam; *p++ = *q;
*p = '\0'; *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. */ /* Insert all matches in the command line. */