From: Peter Stephenson <p.w.stephenson@ntlworld.com>
To: zsh-workers@zsh.org
Subject: Re: Bug: Searching through sufficiently large $historywords causes seg fault
Date: Fri, 12 May 2023 10:28:15 +0100 (BST) [thread overview]
Message-ID: <786956771.10261130.1683883695977@mail.virginmedia.com> (raw)
In-Reply-To: <290263641.10091739.1683707984531@mail.virginmedia.com>
> Tracking down all possible cases where a history word number can be
> calculated wrongly from any possible source is another thing entirely.
> Possibly some DPUTS() in the earlier code are a good idea, as now we
> know it is showing up in error later on trapping it there isn't going
> to help any more.
Here's the only obvious case I can see in normal history management
where you might get a miscalculation, though why is obscure as this
seems only to be connected to skipping a !-history expansion. IF
this pops up hopefully you'll be able to work out how to reproduce
it.
The history reading mechanism from a file remains a suspect as it's
much more obscure, and is consequently harder to instrument usefully.
I'll commit the other patch this weekend: I think we have enough
information to be able to continue searches without having to have
the shell crash for us.
pws
diff --git a/Src/hist.c b/Src/hist.c
index 82d03a840..7e6394406 100644
--- a/Src/hist.c
+++ b/Src/hist.c
@@ -1643,12 +1643,17 @@ hend(Eprog prog)
void
ihwbegin(int offset)
{
+ int pos = hptr - chline + offset;
if (stophist == 2 || (histactive & HA_INWORD) ||
(inbufflags & (INP_ALIAS|INP_HIST)) == INP_ALIAS)
return;
if (chwordpos%2)
chwordpos--; /* make sure we're on a word start, not end */
- chwords[chwordpos++] = hptr - chline + offset;
+ DPUTS1(pos < 0, "History word position < 0 in %s",
+ dupstrpfx(chline, hptr-chline));
+ if (pos < 0)
+ pos = 0;
+ chwords[chwordpos++] = pos;
}
/* Abort current history word, not needed */
next prev parent reply other threads:[~2023-05-12 9:28 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-05-08 8:58 Marlon Richert
2023-05-08 17:01 ` Bart Schaefer
2023-05-09 16:53 ` Bart Schaefer
2023-05-09 16:58 ` Bart Schaefer
2023-05-09 19:01 ` Peter Stephenson
2023-05-09 23:05 ` Bart Schaefer
2023-05-10 8:39 ` Peter Stephenson
2023-05-12 9:28 ` Peter Stephenson [this message]
2023-05-12 16:12 ` 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=786956771.10261130.1683883695977@mail.virginmedia.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).