From helbig@MX.BA-Stuttgart.De  Tue Jul  8 16:05:32 1997
Received: from helbig.informatik.ba-stuttgart.de (rvc1.informatik.ba-stuttgart.de [141.31.112.22])
          by hub.freebsd.org (8.8.5/8.8.5) with ESMTP id QAA14833
          for <FreeBSD-gnats-submit@freebsd.org>; Tue, 8 Jul 1997 16:05:29 -0700 (PDT)
Received: (from root@localhost)
	by helbig.informatik.ba-stuttgart.de (8.8.6/8.8.5) id BAA14379;
	Wed, 9 Jul 1997 01:05:33 +0200 (MET DST)
Message-Id: <199707082305.BAA14379@helbig.informatik.ba-stuttgart.de>
Date: Wed, 9 Jul 1997 01:05:33 +0200 (MET DST)
From: Wolfgang Helbig <helbig@MX.BA-Stuttgart.De>
Reply-To: helbig@MX.BA-Stuttgart.De
To: FreeBSD-gnats-submit@freebsd.org
Subject: libedit's history search is broken
X-Send-Pr-Version: 3.2

>Number:         4064
>Category:       bin
>Synopsis:       libedit's history search is broken
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    msmith@freebsd.org
>State:          closed
>Quarter:
>Keywords:
>Date-Required:
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Tue Jul  8 16:10:01 PDT 1997
>Closed-Date:    Mon Jul 14 06:21:23 PDT 1997
>Last-Modified:  Mon Jul 14 06:24:40 PDT 1997
>Originator:     Wolfgang Helbig
>Release:        FreeBSD 3.0-CURRENT i386
>Organization:
>Environment:

	

>Description:

	The error shows up e. g. in sh(1), which uses the libedit.
	Do a ``set -o vi'' to enable vi style line editing.
	If you search for `ls' in the history, the shell will either
	show all commands that contain a `l', or will beep at you,
	even if there are commands that contain `ls' in the past.

>How-To-Repeat:

	Enter the following commands to get a history.
	# sh
	# set -o vi
	# lll
	# llll

	Now hit the escape key to enter the vi commands, enter
	/llll, to search for the last occurence of the string `llll'
	in the history. Depending on whatever, the shell will show
	you the command `llll', which is correct, or beep at you,
	which is wrong.  Hit the `N'-key to repeat the search, the
	shell might show you `lll', which is wrong, it should beep
	at you instead.

>Fix:

Index: search.c
===================================================================
RCS file: /usr/cvsroot/src/lib/libedit/search.c,v
retrieving revision 1.5
diff -c -r1.5 search.c
*** search.c	1997/06/25 08:14:17	1.5
--- search.c	1997/07/08 21:39:09
***************
*** 464,471 ****
  	    (void)strncpy(tmpbuf, el->el_search.patbuf, sizeof(tmpbuf) - 1);
  	    el->el_search.patbuf[0] = '.';
  	    el->el_search.patbuf[1] = '*';
! 	    (void)strncpy(&el->el_search.patbuf[2], tmpbuf,
! 			   sizeof(el->el_search.patbuf) - 3);
  	    el->el_search.patlen++;
  	    el->el_search.patbuf[el->el_search.patlen++] = '.';
  	    el->el_search.patbuf[el->el_search.patlen++] = '*';
--- 464,470 ----
  	    (void)strncpy(tmpbuf, el->el_search.patbuf, sizeof(tmpbuf) - 1);
  	    el->el_search.patbuf[0] = '.';
  	    el->el_search.patbuf[1] = '*';
! 	    (void)strncpy(&el->el_search.patbuf[2], tmpbuf, EL_BUFSIZ - 3);
  	    el->el_search.patlen++;
  	    el->el_search.patbuf[el->el_search.patlen++] = '.';
  	    el->el_search.patbuf[el->el_search.patlen++] = '*';
***************
*** 479,486 ****
  	tmpbuf[tmplen++] = '*';
  #endif
  	tmpbuf[tmplen] = '\0';
! 	(void)strncpy(el->el_search.patbuf, tmpbuf,
! 		       sizeof(el->el_search.patbuf) - 1);
  	el->el_search.patlen = tmplen;
      }
      el->el_state.lastcmd = (el_action_t) dir; /* avoid c_setpat */
--- 478,484 ----
  	tmpbuf[tmplen++] = '*';
  #endif
  	tmpbuf[tmplen] = '\0';
! 	(void)strncpy(el->el_search.patbuf, tmpbuf, EL_BUFSIZ - 1);
  	el->el_search.patlen = tmplen;
      }
      el->el_state.lastcmd = (el_action_t) dir; /* avoid c_setpat */
>Release-Note:
>Audit-Trail:
State-Changed-From-To: open->closed 
State-Changed-By: msmith 
State-Changed-When: Mon Jul 14 06:21:23 PDT 1997 
State-Changed-Why:  
Fixed in r1.6 by applying suppliedpatch. 


Responsible-Changed-From-To: freebsd-bugs->msmith@freebsd.org 
Responsible-Changed-By: msmith 
Responsible-Changed-When: Mon Jul 14 06:21:23 PDT 1997 
Responsible-Changed-Why:  

I broke it, I'll fix it. 
>Unformatted:
