zsh-workers
 help / color / mirror / 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
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

zsh-workers

This inbox may be cloned and mirrored by anyone:

	git clone --mirror https://inbox.vuxu.org/zsh-workers

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V1 zsh-workers zsh-workers/ https://inbox.vuxu.org/zsh-workers \
		zsh-workers@zsh.org
	public-inbox-index zsh-workers

Example config snippet for mirrors.
Newsgroup available over NNTP:
	nntp://inbox.vuxu.org/vuxu.archive.zsh.workers


code repositories for the project(s) associated with this inbox:

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

AGPL code for this site: git clone https://public-inbox.org/public-inbox.git