zsh-workers
 help / color / mirror / code / Atom feed
From: "Jun T." <takimoto-j@kba.biglobe.ne.jp>
To: zsh-workers@zsh.org
Subject: [PATCH] fix unmeta_one() (double counting Meta)
Date: Sat, 22 Apr 2017 02:44:18 +0900	[thread overview]
Message-ID: <8C69FFF6-75BB-48F0-8603-B18B3AB9C52C@kba.biglobe.ne.jp> (raw)

unmeta_one() (in utils.c) seems to have a simple problem.
It calls mb_metacharlenconv_r(), whose return value already
includes the number of extra bytes for Meta. So taking
account of them at lines 4814-4819 makes the value of '*sz'
too large.

This leads to the following segfalut:

% zsh -f
% autoload -Uz compinit; compinit
% zstyle ':completion:*' matcher-list 'm:{a-z}={A-Z}'
You may use any matcher you like. Then
% ls い<TAB><TAB>      # い = U+3044, UTF-8: e3 81 84
hitting tab one or two times and the zsh crashes.

The segfalut is in cfp_matcher_pats(), at computil.c:4488;
the pointer mp has an invalid value.

When unmeta_one(tmp, &cl) is called at line 4496,
    tmp = add = metafy(い) = 0xe3 0x81 0x83 0xa4.
But unmeta_one(tmp, &cl) sets cl to 5, not 4, and the
variable tl becomes negative. Thus the loop doesn't
terminate until it crashes.


diff --git a/Src/utils.c b/Src/utils.c
index 9701ea7..ea4b34b 100644
--- a/Src/utils.c
+++ b/Src/utils.c
@@ -4797,7 +4797,6 @@ unmeta_one(const char *in, int *sz)
     convchar_t wc;
     int newsz;
 #ifdef MULTIBYTE_SUPPORT
-    int ulen;
     mbstate_t wstate;
 #endif
 
@@ -4810,13 +4809,7 @@ unmeta_one(const char *in, int *sz)
 
 #ifdef MULTIBYTE_SUPPORT
     memset(&wstate, 0, sizeof(wstate));
-    ulen = mb_metacharlenconv_r(in, &wc, &wstate);
-    while (ulen-- > 0) {
-	if (in[*sz] == Meta)
-	    *sz += 2;
-	else
-	    *sz += 1;
-    }
+    *sz = mb_metacharlenconv_r(in, &wc, &wstate);
 #else
     if (in[0] == Meta) {
       *sz = 2;






                 reply	other threads:[~2017-04-21 18:36 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=8C69FFF6-75BB-48F0-8603-B18B3AB9C52C@kba.biglobe.ne.jp \
    --to=takimoto-j@kba.biglobe.ne.jp \
    --cc=zsh-workers@zsh.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).