zsh-workers
 help / color / mirror / code / Atom feed
From: Bart Schaefer <schaefer@brasslantern.com>
To: Zsh hackers list <zsh-workers@zsh.org>
Cc: Carl Agrell <caagr98@gmail.com>
Subject: Re: getjobtext() gives invalid utf8, leading to segfault
Date: Sun, 8 Aug 2021 22:33:36 -0700	[thread overview]
Message-ID: <CAH+w=7Za3Qyva_oz0XaJXLurj0jjk2oC2_KrdCC3Z8ncMaOU2g@mail.gmail.com> (raw)
In-Reply-To: <CAHYJk3S=iKXpGKq95DjhD-89xJckq-yeDHYdjBjqYDDY-C3JOQ@mail.gmail.com>

On Sun, Aug 8, 2021 at 7:11 PM Mikael Magnusson <mikachu@gmail.com> wrote:
>
> 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

Does it seem odd to anyone that (!*s) is one of the cases that
triggers that warning, but in the non-DEBUG case it doesn't end the
loop?

The real problem, though:

On Sun, Aug 8, 2021 at 10:14 AM Carl Agrell <caagr98@gmail.com> wrote:
>
> Looking through the source, it looks like this string is created by
> getjobtext().

getjobtext() loads the string into a fixed-size buffer and then
unconditionally puts a '\0' in the last byte of that buffer, which
cuts off the metacharacter in the middle.

Following is the minimal fix, but nothing else in text.c refers to the
Meta constant, so perhaps someone has a better suggestion?

diff --git a/Src/text.c b/Src/text.c
index 4bf88f2e2..5cd7685fd 100644
--- a/Src/text.c
+++ b/Src/text.c
@@ -335,6 +335,8 @@ getjobtext(Eprog prog, Wordcode c)
     tlim = tptr + JOBTEXTSIZE - 1;
     tjob = 1;
     gettext2(&s);
+    if (tptr[-1] == Meta)
+       --tptr;
     *tptr = '\0';
     freeeprog(prog);           /* mark as unused */
     untokenize(jbuf);


      reply	other threads:[~2021-08-09  5:34 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
2021-08-09  5:33   ` Bart Schaefer [this message]

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='CAH+w=7Za3Qyva_oz0XaJXLurj0jjk2oC2_KrdCC3Z8ncMaOU2g@mail.gmail.com' \
    --to=schaefer@brasslantern.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).