zsh-workers
 help / color / mirror / code / Atom feed
* PATCH: zshaddhistory hook can get unterminated string
@ 2008-09-18  9:39 Peter Stephenson
  0 siblings, 0 replies; only message in thread
From: Peter Stephenson @ 2008-09-18  9:39 UTC (permalink / raw)
  To: Zsh hackers list

There are now hook functions called when a history line is about to be
saved.  I've seen these getting garbage at the end of the argument
passed in, which is the line about to be processed for saving.  This is
presumably because the history line hasn't been terminated.  I haven't
verified that fixing this makes the problem go away (it's intermittent),
but it seems like the right thing to do anyway.

Index: Src/hist.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/hist.c,v
retrieving revision 1.83
diff -u -r1.83 hist.c
--- Src/hist.c	10 Sep 2008 19:02:27 -0000	1.83
+++ Src/hist.c	18 Sep 2008 09:34:49 -0000
@@ -1129,7 +1129,13 @@
     if (hist_ignore_all_dups != isset(HISTIGNOREALLDUPS)
      && (hist_ignore_all_dups = isset(HISTIGNOREALLDUPS)) != 0)
 	histremovedups();
-    
+
+    /*
+     * Added the following in case the test "hptr < chline + 1"
+     * is more than just paranoia.
+     */
+    DPUTS(hptr < chline, "History end pointer off start of line");
+    *hptr = '\0';
     addlinknode(hookargs, "zshaddhistory");
     addlinknode(hookargs, chline);
     callhookfunc("zshaddhistory", hookargs, 1, &hookret);
@@ -1144,7 +1150,6 @@
     if (hptr < chline + 1)
 	save = 0;
     else {
-	*hptr = '\0';
 	if (hptr[-1] == '\n') {
 	    if (chline[1]) {
 		*--hptr = '\0';


-- 
Peter Stephenson <pws@csr.com>                  Software Engineer
CSR PLC, Churchill House, Cambridge Business Park, Cowley Road
Cambridge, CB4 0WZ, UK                          Tel: +44 (0)1223 692070


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2008-09-18  9:40 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-09-18  9:39 PATCH: zshaddhistory hook can get unterminated string Peter Stephenson

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).