Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

PATCH: zshaddhistory hook can get unterminated string



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@xxxxxxx>                  Software Engineer
CSR PLC, Churchill House, Cambridge Business Park, Cowley Road
Cambridge, CB4 0WZ, UK                          Tel: +44 (0)1223 692070



Messages sorted by: Reverse Date, Date, Thread, Author