zsh-workers
 help / color / mirror / code / Atom feed
From: Peter Stephenson <p.w.stephenson@ntlworld.com>
To: Zsh hackers list <zsh-workers@zsh.org>
Subject: Re: [BUG] sigsegv
Date: Sun, 30 Apr 2023 18:30:59 +0100	[thread overview]
Message-ID: <9a4279398cabea525bb77662418ad536be7770bc.camel@ntlworld.com> (raw)
In-Reply-To: <CAKc7PVDV98OLcb+0QY7ANmkLdMOKV=TncgsOfZqa=Cmoap+yiw@mail.gmail.com>

On Sat, 2023-04-29 at 10:52 +0000, Sebastian Gniazdowski wrote:
> It says "incomplete sequence \339"  although egrep $'\330' ~/.zhistory
> doesn't return anything…

So it looks like this is probably confusion over bad or incomplete
multibyte characters again.

Rather than bufferwords() --- I think that's not relevant at this point
--- this could be the code that reads a history line back into the buffer
and divides it into words getting confused.  This is different from
the code that adds to a history line when it's first generated and
likely to be less accurate --- and also fits better with the
reproducibility of this problem.

Anyway, given there's no single place where the line originates,
and given that we're probably not going to be able to turn it into
a proper line if the there's not a complete character sequence,
safety at the point in question is probably the best we've got.

See if this helps.

pws

diff --git a/Src/Modules/parameter.c b/Src/Modules/parameter.c
index 96a211c69..2067f5bab 100644
--- a/Src/Modules/parameter.c
+++ b/Src/Modules/parameter.c
@@ -1233,9 +1233,16 @@ histwgetfn(UNUSED(Param pm))
             pushnode(l, getdata(n));
 
     while (he) {
+	char *hstr = he->node.nam;
+	int len = strlen(hstr);
 	for (iw = he->nwords - 1; iw >= 0; iw--) {
-	    h = he->node.nam + he->words[iw * 2];
-	    e = he->node.nam + he->words[iw * 2 + 1];
+	    int wbegin = he->words[iw * 2];
+	    int wend = he->words[iw * 2 + 1];
+
+	    if (wbegin >= len || wend > len)
+		break;
+	    h = hstr + wbegin;
+	    e = hstr + wend;
 	    sav = *e;
 	    *e = '\0';
 	    addlinknode(l, dupstring(h));



  parent reply	other threads:[~2023-04-30 17:31 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-04-25 13:48 Sebastian Gniazdowski
2023-04-25 13:56 ` Peter Stephenson
2023-04-28 11:25   ` Sebastian Gniazdowski
2023-04-28 11:41     ` Peter Stephenson
2023-04-28 14:13       ` Sebastian Gniazdowski
2023-04-28 14:22         ` Peter Stephenson
2023-04-29 10:52           ` Sebastian Gniazdowski
2023-04-30  9:51             ` Sebastian Gniazdowski
2023-04-30 17:30             ` Peter Stephenson [this message]
2023-05-03 15:35               ` Sebastian Gniazdowski
2023-05-03 15:56                 ` Sebastian Gniazdowski
2023-05-03 16:25                 ` Peter Stephenson
2023-05-03 21:13                   ` Bart Schaefer
     [not found]                     ` <CAKc7PVDt6hS26DxC3hDE-ziMXm-K1jqbJXghynpp-ZhpdN_LLw@mail.gmail.com>
2023-05-04 15:01                       ` Bart Schaefer
2023-05-05 18:54                   ` Peter Stephenson

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=9a4279398cabea525bb77662418ad536be7770bc.camel@ntlworld.com \
    --to=p.w.stephenson@ntlworld.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).