mirror of
git://git.code.sf.net/p/zsh/code
synced 2025-10-06 09:01:13 +02:00
25989: fix crash in matching
This commit is contained in:
parent
6dbf2f2f4a
commit
d41c6098b4
2 changed files with 32 additions and 36 deletions
|
@ -1,3 +1,8 @@
|
||||||
|
2008-11-02 Peter Stephenson <p.w.stephenson@ntlworld.com>
|
||||||
|
|
||||||
|
* 25989: Src/Zle/computil.c: Slight improvement for multibyte
|
||||||
|
characters in matching to prevent crash.
|
||||||
|
|
||||||
2008-11-02 Clint Adams <clint@zsh.org>
|
2008-11-02 Clint Adams <clint@zsh.org>
|
||||||
|
|
||||||
* 25988: Completion/Darwin/Command/_fink,
|
* 25988: Completion/Darwin/Command/_fink,
|
||||||
|
|
|
@ -4024,7 +4024,17 @@ cfp_matcher_range(Cmatcher *ms, char *add)
|
||||||
* management is difficult.
|
* management is difficult.
|
||||||
*/
|
*/
|
||||||
for (;;) {
|
for (;;) {
|
||||||
|
MB_METACHARINIT();
|
||||||
for (mp = ms; *add; ) {
|
for (mp = ms; *add; ) {
|
||||||
|
convchar_t addc;
|
||||||
|
int addlen;
|
||||||
|
|
||||||
|
addlen = MB_METACHARLENCONV(add, &addc);
|
||||||
|
#ifdef MULTIBYTE_SUPPORT
|
||||||
|
if (addc == WEOF)
|
||||||
|
addc = (wchar_t)(*p == Meta ? p[1] ^ 32 : *p);
|
||||||
|
#endif
|
||||||
|
|
||||||
if (!(m = *mp)) {
|
if (!(m = *mp)) {
|
||||||
/*
|
/*
|
||||||
* No matcher, so just match the character
|
* No matcher, so just match the character
|
||||||
|
@ -4034,13 +4044,10 @@ cfp_matcher_range(Cmatcher *ms, char *add)
|
||||||
* metacharacter?
|
* metacharacter?
|
||||||
*/
|
*/
|
||||||
if (ret) {
|
if (ret) {
|
||||||
if (*add == Meta) {
|
memcpy(p, add, addlen);
|
||||||
*p++ = Meta;
|
p += addlen;
|
||||||
*p++ = add[1];
|
|
||||||
} else
|
} else
|
||||||
*p++ = *add;
|
len += addlen;
|
||||||
} else
|
|
||||||
len += (*add == Meta) ? 2 : 1;
|
|
||||||
} else if (m->flags & CMF_RIGHT) {
|
} else if (m->flags & CMF_RIGHT) {
|
||||||
/*
|
/*
|
||||||
* Right-anchored: match anything followed
|
* Right-anchored: match anything followed
|
||||||
|
@ -4049,16 +4056,12 @@ cfp_matcher_range(Cmatcher *ms, char *add)
|
||||||
if (ret) {
|
if (ret) {
|
||||||
*p++ = '*';
|
*p++ = '*';
|
||||||
/* TODO: quote again? */
|
/* TODO: quote again? */
|
||||||
if (*add == Meta) {
|
memcpy(p, add, addlen);
|
||||||
*p++ = Meta;
|
p += addlen;
|
||||||
*p++ = add[1];
|
|
||||||
} else
|
} else
|
||||||
*p++ = *add;
|
len += addlen + 1;
|
||||||
} else
|
|
||||||
len += (*add == Meta) ? 3 : 2;
|
|
||||||
} else {
|
} else {
|
||||||
/* The usual set of matcher possibilities. */
|
/* The usual set of matcher possibilities. */
|
||||||
int chr = (*add == Meta) ? add[1] ^ 32 : *add;
|
|
||||||
int ind;
|
int ind;
|
||||||
if (m->line->tp == CPAT_EQUIV &&
|
if (m->line->tp == CPAT_EQUIV &&
|
||||||
m->word->tp == CPAT_EQUIV) {
|
m->word->tp == CPAT_EQUIV) {
|
||||||
|
@ -4073,21 +4076,17 @@ cfp_matcher_range(Cmatcher *ms, char *add)
|
||||||
*/
|
*/
|
||||||
if (ret) {
|
if (ret) {
|
||||||
*p++ = '[';
|
*p++ = '[';
|
||||||
if (*add == Meta) {
|
memcpy(p, add, addlen);
|
||||||
*p++ = Meta;
|
p += addlen;
|
||||||
*p++ = add[1];
|
|
||||||
} else
|
} else
|
||||||
*p++ = *add;
|
len += addlen + 1;
|
||||||
} else
|
if (PATMATCHRANGE(m->line->u.str, addc, &ind, &mt)) {
|
||||||
len += (*add == Meta) ? 3 : 2;
|
|
||||||
if (PATMATCHRANGE(m->line->u.str, CONVCAST(chr),
|
|
||||||
&ind, &mt)) {
|
|
||||||
/*
|
/*
|
||||||
* Find the equivalent match for ind in the
|
* Find the equivalent match for ind in the
|
||||||
* word pattern.
|
* word pattern.
|
||||||
*/
|
*/
|
||||||
if ((ind = pattern_match_equivalence
|
if ((ind = pattern_match_equivalence
|
||||||
(m->word, ind, mt, CONVCAST(chr))) != -1) {
|
(m->word, ind, mt, addc)) != -1) {
|
||||||
if (ret) {
|
if (ret) {
|
||||||
if (imeta(ind)) {
|
if (imeta(ind)) {
|
||||||
*p++ = Meta;
|
*p++ = Meta;
|
||||||
|
@ -4159,7 +4158,7 @@ cfp_matcher_range(Cmatcher *ms, char *add)
|
||||||
* if *add is ] and ] is also the first
|
* if *add is ] and ] is also the first
|
||||||
* character in the range.
|
* character in the range.
|
||||||
*/
|
*/
|
||||||
addadd = !pattern_match1(m->word, CONVCAST(chr), &mt);
|
addadd = !pattern_match1(m->word, addc, &mt);
|
||||||
if (addadd && *add == ']') {
|
if (addadd && *add == ']') {
|
||||||
if (ret)
|
if (ret)
|
||||||
*p++ = *add;
|
*p++ = *add;
|
||||||
|
@ -4196,13 +4195,10 @@ cfp_matcher_range(Cmatcher *ms, char *add)
|
||||||
}
|
}
|
||||||
if (addadd && *add != ']') {
|
if (addadd && *add != ']') {
|
||||||
if (ret) {
|
if (ret) {
|
||||||
if (imeta(*add)) {
|
memcpy(p, add, addlen);
|
||||||
*p++ = Meta;
|
p += addlen;
|
||||||
*p++ = *add ^ 32;
|
|
||||||
} else
|
} else
|
||||||
*p++ = *add;
|
len += addlen;
|
||||||
} else
|
|
||||||
len += imeta(*add) ? 2 : 1;
|
|
||||||
}
|
}
|
||||||
if (ret)
|
if (ret)
|
||||||
*p++ = ']';
|
*p++ = ']';
|
||||||
|
@ -4219,14 +4215,9 @@ cfp_matcher_range(Cmatcher *ms, char *add)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (*add == Meta) {
|
add += addlen;
|
||||||
add += 2;
|
|
||||||
mp += 2;
|
|
||||||
} else {
|
|
||||||
add++;
|
|
||||||
mp++;
|
mp++;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
if (ret) {
|
if (ret) {
|
||||||
*p = '\0';
|
*p = '\0';
|
||||||
return ret;
|
return ret;
|
||||||
|
|
Loading…
Reference in a new issue