Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: [BUG] SIGSEGV under certain circumstances
- X-seq: zsh-workers 40754
- From: Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx>
- To: "zsh-workers@xxxxxxx" <zsh-workers@xxxxxxx>
- Subject: Re: [BUG] SIGSEGV under certain circumstances
- Date: Sun, 5 Mar 2017 16:23:32 -0800
- Authentication-results: amavisd4.gkg.net (amavisd-new); dkim=pass (2048-bit key) header.d=brasslantern-com.20150623.gappssmtp.com
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=brasslantern-com.20150623.gappssmtp.com; s=20150623; h=from:message-id:date:in-reply-to:comments:references:to:subject :mime-version; bh=ct4H/9gwKPDUBg3z7Tb/IztrR6z4yMlwhtSefIS96dQ=; b=jdNOK34Ly+PmedPGlspThcrpByFVxdzncp99UGvLinZkT4971udtPRhZVCcZom1Fkd Mqfll6QZeh/AqNkPgooYE6ts8zaOGWu5rmyJ4hbAha84haBSyfzeT5YHj/Wj+71cwJRQ 1CyZK58KYORB6YvCF/kG3EY2pC+YLd2OuqnVrVzPgftXXn/JeciI7zW6D2HDrrmhOxuI 59S02iUG8zp/cwvk1eJJJJVKo1AqdTJaVodFIvg/nzxGkAozwk0z/xnb1TCtSLheN8XQ hTe0X2dfPMRy2ePDKCuqOQuZjRe/EJYisfqxFlpxhx1ADuYffx7Pk7VEiu6M0QOYvaRb jPzw==
- In-reply-to: <CAH+w=7ZYFESm_Bc+3N6DbzqEKBG_J8dH3xdToNWNhjn4bhNm8w@mail.gmail.com>
- List-help: <mailto:zsh-workers-help@zsh.org>
- List-id: Zsh Workers List <zsh-workers.zsh.org>
- List-post: <mailto:zsh-workers@zsh.org>
- Mailing-list: contact zsh-workers-help@xxxxxxx; run by ezmlm
- References: <CAMNjDR1CUaw2AXbEDLP94R=4VCNj1yc=d3OcVj=tO6FZXAEqPQ@mail.gmail.com> <170304151137.ZM30694@torch.brasslantern.com> <CAMNjDR0A-c=Q3AD1hCrbas3YRJ1VXp68KbSLcdMDFH7JQYNdng@mail.gmail.com> <170305080054.ZM24832@torch.brasslantern.com> <20170305161720.6f3773d6@ntlworld.com> <170305104239.ZM25231@torch.brasslantern.com> <5096E600-D76C-4F71-BE93-C46F256BA7D7@ntlworld.com> <170305134513.ZM26364@torch.brasslantern.com> <20170305224100.GA18432@fujitsu.shahaf.local2> <CAH+w=7ZNdQ9XsXSD2znAj=cZNR0rLK7+tRiH1XkQNk=61-AUpw@mail.gmail.com> <CAH+w=7ZYFESm_Bc+3N6DbzqEKBG_J8dH3xdToNWNhjn4bhNm8w@mail.gmail.com>
On Mar 5, 3:07pm, Bart Schaefer wrote:
}
} Also, it seems to me cl needs to be the number of bytes compared by
} pattern_match(), which is not always just 1 or 2 with wide characters.
Let's try this? Hopefully zero'ing the mbstate_t is both correct and
not too time consuming in unmeta_one(). It'd be nice if pattern_match()
could return the size but there are too many possibilities (including a
successful match of zero length, it seems).
This is against master, NOT on top of my previous patch.
diff --git a/Src/Zle/compmatch.c b/Src/Zle/compmatch.c
index aedf463..1cdbb8a 100644
--- a/Src/Zle/compmatch.c
+++ b/Src/Zle/compmatch.c
@@ -1548,27 +1548,11 @@ pattern_match(Cpattern p, char *s, Cpattern wp, char *ws)
{
convchar_t c, wc;
convchar_t ind, wind;
- int len = 0, wlen, mt, wmt;
-#ifdef MULTIBYTE_SUPPORT
- mbstate_t lstate, wstate;
-
- memset(&lstate, 0, sizeof(lstate));
- memset(&wstate, 0, sizeof(wstate));
-#endif
+ int len = 0, wlen = 0, mt, wmt;
while (p && wp && *s && *ws) {
/* First test the word character */
-#ifdef MULTIBYTE_SUPPORT
- wlen = mb_metacharlenconv_r(ws, &wc, &wstate);
-#else
- if (*ws == Meta) {
- wc = STOUC(ws[1]) ^ 32;
- wlen = 2;
- } else {
- wc = STOUC(*ws);
- wlen = 1;
- }
-#endif
+ wc = unmeta_one(ws, &wlen);
wind = pattern_match1(wp, wc, &wmt);
if (!wind)
return 0;
@@ -1576,18 +1560,7 @@ pattern_match(Cpattern p, char *s, Cpattern wp, char *ws)
/*
* Now the line character.
*/
-#ifdef MULTIBYTE_SUPPORT
- len = mb_metacharlenconv_r(s, &c, &lstate);
-#else
- /* We have the character itself. */
- if (*s == Meta) {
- c = STOUC(s[1]) ^ 32;
- len = 2;
- } else {
- c = STOUC(*s);
- len = 1;
- }
-#endif
+ c = unmeta_one(s, &len);
/*
* If either is "?", they match each other; no further tests.
* Apply this even if the character wasn't convertable;
@@ -1627,17 +1600,7 @@ pattern_match(Cpattern p, char *s, Cpattern wp, char *ws)
}
while (p && *s) {
-#ifdef MULTIBYTE_SUPPORT
- len = mb_metacharlenconv_r(s, &c, &lstate);
-#else
- if (*s == Meta) {
- c = STOUC(s[1]) ^ 32;
- len = 2;
- } else {
- c = STOUC(*s);
- len = 1;
- }
-#endif
+ c = unmeta_one(s, &len);
if (!pattern_match1(p, c, &mt))
return 0;
p = p->next;
@@ -1645,17 +1608,7 @@ pattern_match(Cpattern p, char *s, Cpattern wp, char *ws)
}
while (wp && *ws) {
-#ifdef MULTIBYTE_SUPPORT
- wlen = mb_metacharlenconv_r(ws, &wc, &wstate);
-#else
- if (*ws == Meta) {
- wc = STOUC(ws[1]) ^ 32;
- wlen = 2;
- } else {
- wc = STOUC(*ws);
- wlen = 1;
- }
-#endif
+ wc = unmeta_one(ws, &wlen);
if (!pattern_match1(wp, wc, &wmt))
return 0;
wp = wp->next;
diff --git a/Src/Zle/computil.c b/Src/Zle/computil.c
index 325da6d..4ea409d 100644
--- a/Src/Zle/computil.c
+++ b/Src/Zle/computil.c
@@ -4485,10 +4485,10 @@ cfp_matcher_pats(char *matcher, char *add)
} else
*mp = m;
}
- cl = (*tmp == Meta) ? 2 : 1;
+ (void) unmeta_one(tmp, &cl);
tl -= cl;
tmp += cl;
- mp += cl;
+ mp++;
}
} else {
stopp = m->line;
@@ -4505,10 +4505,10 @@ cfp_matcher_pats(char *matcher, char *add)
} else
*mp = m;
}
- cl = (*tmp == Meta) ? 2 : 1;
+ (void) unmeta_one(tmp, &cl);
tl -= cl;
tmp += cl;
- mp += cl;
+ mp++;
}
} else if (m->llen) {
stopp = m->line;
@@ -4531,7 +4531,7 @@ cfp_matcher_pats(char *matcher, char *add)
al = tmp - add;
break;
}
- cl = (*tmp == Meta) ? 2 : 1;
+ (void) unmeta_one(tmp, &cl);
tl -= cl;
tmp += cl;
}
diff --git a/Src/utils.c b/Src/utils.c
index 7f3ddad..58983d3 100644
--- a/Src/utils.c
+++ b/Src/utils.c
@@ -4788,6 +4788,56 @@ unmeta(const char *file_name)
}
/*
+ * Unmetafy just one character and store the number of bytes it occupied.
+ */
+/**/
+mod_export convchar_t
+unmeta_one(const char *in, int *sz)
+{
+#ifdef MB_CUR_MAX
+ VARARR(char,out,MB_CUR_MAX+1);
+#else
+#define MB_CUR_MAX 2
+ char out[MB_CUR_MAX+1];
+#endif
+ convchar_t wc;
+ char *p;
+ const char *t;
+ int newsz;
+#ifdef MULTIBYTE_SUPPORT
+ int ulen;
+ mbstate_t wstate;
+#endif
+
+ if (!sz)
+ sz = &newsz;
+ *sz = 0;
+
+ if (!in)
+ return 0;
+
+ for (t = in, p = out; *t && (p - out <= MB_CUR_MAX); p++)
+ if ((*p = *t++) == Meta && *t)
+ *p = *t++ ^ 32;
+ *p = '\0'; /* Unnecessary? */
+
+#ifdef MULTIBYTE_SUPPORT
+ memset(&wstate, 0, sizeof(wstate));
+ ulen = mb_metacharlenconv_r(out, &wc, &wstate);
+ while (ulen-- > 0) {
+ if (in[*sz] == Meta)
+ *sz += 2;
+ else
+ *sz += 1;
+ }
+#else
+ *sz = p - out;
+ wc = STOUC(out[0]);
+#endif
+ return wc;
+}
+
+/*
* Unmetafy and compare two strings, comparing unsigned character values.
* "a\0" sorts after "a".
*
Messages sorted by:
Reverse Date,
Date,
Thread,
Author