Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: getjobtext() gives invalid utf8, leading to segfault
- X-seq: zsh-workers 49266
- From: Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx>
- To: Zsh hackers list <zsh-workers@xxxxxxx>
- Cc: Carl Agrell <caagr98@xxxxxxxxx>
- Subject: Re: getjobtext() gives invalid utf8, leading to segfault
- Date: Sun, 8 Aug 2021 22:33:36 -0700
- Archived-at: <https://zsh.org/workers/49266>
- In-reply-to: <CAHYJk3S=iKXpGKq95DjhD-89xJckq-yeDHYdjBjqYDDY-C3JOQ@mail.gmail.com>
- List-id: <zsh-workers.zsh.org>
- References: <CALd=4svbYzbALvFBoAEW-uqyPaEuK+CE8e1HsKqyGvZP-vp6eg@mail.gmail.com> <CAHYJk3S=iKXpGKq95DjhD-89xJckq-yeDHYdjBjqYDDY-C3JOQ@mail.gmail.com>
On Sun, Aug 8, 2021 at 7:11 PM Mikael Magnusson <mikachu@xxxxxxxxx> 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@xxxxxxxxx> 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);
Messages sorted by:
Reverse Date,
Date,
Thread,
Author