zsh-workers
 help / color / mirror / code / Atom feed
From: Peter Stephenson <p.w.stephenson@ntlworld.com>
To: zsh-workers@zsh.org
Subject: Re: Obscure zsh history overflow with segfault
Date: Thu, 26 Jan 2012 20:57:02 +0000	[thread overview]
Message-ID: <20120126205702.6c3e2ab2@pws-pc.ntlworld.com> (raw)
In-Reply-To: <120124122819.ZM31632@torch.brasslantern.com>

On Tue, 24 Jan 2012 12:28:19 -0800
Bart Schaefer <schaefer@brasslantern.com> wrote:

> On Jan 21,  4:39am, Daniel Shahaf wrote:
> }
> } Apparently, 'r 100 foo' should re-execute the portion of your history
> } from event #100 to event 'foo'.
> } 
> } Sounds like a bad idea...
> 
> Interesting.  Here we are:
> 
> 1516                /*
> 1517                 * Nasty behaviour results if we use the current history
> 1518                 * line here.  Treat it as if it doesn't exist, unless
> 1519                 * that gives us an empty range.
> 1520                 */
> 1521                if (last >= curhist) {
> 1522                    last = curhist - 1;
> 1523                    if (first > last) {
> 1524                        unqueue_signals();
> 1525                        zwarnnam("fc",
> 1526                          "current history line would recurse endlessly, aborted");
> 1527                        fclose(out);
> 1528                        unlink(fil);
> 1529                        return 1;
> 1530                    }
> 1531                }
> 
> In the situation in this bug, first > last is true but last >= curhist
> is false.  I believe that means that even though this is an infinite
> loop, we don't detect that it will be.

I'm not really following the problem, but do you mean something like
this?

Index: Src/builtin.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/builtin.c,v
retrieving revision 1.254
diff -p -u -r1.254 builtin.c
--- Src/builtin.c	29 Aug 2011 17:21:40 -0000	1.254
+++ Src/builtin.c	26 Jan 2012 20:56:28 -0000
@@ -1652,6 +1652,12 @@ fclist(FILE *f, Options ops, zlong first
 	last = first;
 	first = tmp;
     }
+    if (first > last) {
+	zwarnnam("fc", "history events are in wrong order, aborted");
+	if (f != stdout)
+	    fclose(f);
+	return 1;
+    }
     /* suppress "no substitution" warning if no substitution is requested */
     if (!subs)
 	fclistdone = 1;

-- 
Peter Stephenson <p.w.stephenson@ntlworld.com>
Web page now at http://homepage.ntlworld.com/p.w.stephenson/


  reply	other threads:[~2012-01-26 20:57 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-01-20 19:42 Christian Neukirchen
2012-01-21  2:39 ` Daniel Shahaf
2012-01-24 20:28   ` Bart Schaefer
2012-01-26 20:57     ` Peter Stephenson [this message]
2012-01-27  4:59       ` 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=20120126205702.6c3e2ab2@pws-pc.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).