zsh-workers
 help / color / mirror / code / Atom feed
From: Mikael Magnusson <mikachu@gmail.com>
To: Carl Agrell <caagr98@gmail.com>
Cc: zsh-workers@zsh.org
Subject: Re: getjobtext() gives invalid utf8, leading to segfault
Date: Mon, 9 Aug 2021 04:10:06 +0200	[thread overview]
Message-ID: <CAHYJk3S=iKXpGKq95DjhD-89xJckq-yeDHYdjBjqYDDY-C3JOQ@mail.gmail.com> (raw)
In-Reply-To: <CALd=4svbYzbALvFBoAEW-uqyPaEuK+CE8e1HsKqyGvZP-vp6eg@mail.gmail.com>

On 8/8/21, Carl Agrell <caagr98@gmail.com> wrote:
> With the powerlevel10k prompt, running either of these two commands
> causes the shell to segfault:
>     $
> AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA月光
>     $
> AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA月
> The AAAs can be replaced with anything as long as the length is
> unchanged (did not test with non-ascii though). Changing the kanji at
> the end usually makes it not crash, strangely enough.
>
> A minimal zshrc creating the same crash is
>     _preexec() {
>         [[ $2 == "" ]]
>     }
>     preexec_functions=(_preexec)
>
> If we echo $2 instead of comparing it, it is printed as
>     AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA月�
> hinting that it's a multibyte error. Curiously, /bin/echo instead
> gives 月元 at the end.
>
> Looking through the source, it looks like this string is created by
> getjobtext(). This hints that similar errors might be seen in other
> places where jobs are displayed, and indeed:
>     $ cat /dev/stdin
> AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA月
>     ^Z
>     zsh: suspended  cat /dev/stdin
> AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA會
>
> I am running `zsh 5.8 (x86_64-pc-linux-gnu)`, the one that is current
> packaged in Arch Linux.

Running in debug mode prints the message:
BUG: substring ends in the middle of a metachar in ztrsub()
and breaking here in gdb gives the following backtrace:
(gdb) bt
#0  ztrsub (t=0x7ffff7fe91fd "", s=0x7ffff7fe91fd "") at utils.c:5187
#1  0x0000000000496ac6 in patallocstr (prog=0x701320,
    string=0x7ffff7fe91b0 'A' <repeats 68 times>, "惼\203\250僥\203",
stringlen=77,
    unmetalen=-1, force=0, patstralloc=0x7fffffffc9b0) at pattern.c:2138
#2  0x0000000000496ec1 in pattryrefs (prog=0x701320,
    string=0x7ffff7fe91b0 'A' <repeats 68 times>, "惼\203\250僥\203",
stringlen=77,
    unmetalenin=-1, patstralloc=0x7fffffffc9b0, patoffset=0, nump=0x0,
begp=0x0, endp=0x0)
    at pattern.c:2312
#3  0x0000000000496ce0 in pattry (prog=0x701320,
    string=0x7ffff7fe91b0 'A' <repeats 68 times>, "惼\203\250僥\203") at
pattern.c:2214
#4  0x000000000042cbca in evalcond (state=0x7fffffffcfc0,
fromtest=0x0) at cond.c:322
#5  0x000000000043c36d in execcond (state=0x7fffffffcfc0, do_exec=0)
at exec.c:5122
#6  0x0000000000430dee in execsimple (state=0x7fffffffcfc0) at exec.c:1276
#7  0x000000000043126c in execlist (state=0x7fffffffcfc0,
dont_change_job=1, exiting=0)
    at exec.c:1404
#8  0x0000000000430aa3 in execode (p=0x7198f0, dont_change_job=1, exiting=0,
    context=0x4c7eea "shfunc") at exec.c:1218
#9  0x000000000043ebec in runshfunc (prog=0x7198f0, wrap=0x0,
name=0x7ffff7fe9170 "preexec")
    at exec.c:6066
#10 0x000000000043e41e in doshfunc (shfunc=0x719310,
doshargs=0x7ffff7ff4b50, noreturnval=1)
    at exec.c:5916
#11 0x00000000004b5ce6 in callhookfunc (name=0x4ca0cb "preexec",
lnklst=0x7ffff7ff4b50,
    arrayp=1, retval=0x0) at utils.c:1530
#12 0x0000000000457022 in loop (toplevel=1, justonce=0) at init.c:198
#13 0x000000000045aee1 in zsh_main (argc=2, argv=0x7fffffffd638) at init.c:1799
#14 0x000000000040f9d6 in main (argc=2, argv=0x7fffffffd638) at ./main.c:93



-- 
Mikael Magnusson


  reply	other threads:[~2021-08-09  2:10 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-08-08 17:14 Carl Agrell
2021-08-09  2:10 ` Mikael Magnusson [this message]
2021-08-09  5:33   ` Bart Schaefer

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='CAHYJk3S=iKXpGKq95DjhD-89xJckq-yeDHYdjBjqYDDY-C3JOQ@mail.gmail.com' \
    --to=mikachu@gmail.com \
    --cc=caagr98@gmail.com \
    --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).