Subject: bin/6081: libedit's search doesn work in /bin/sh's vi-mode
To: None <gnats-bugs@gnats.netbsd.org>
From: None <helbig@Informatik.BA-Stuttgart.DE>
List: netbsd-bugs
Date: 08/31/1998 22:59:00
>Number:         6081
>Category:       bin
>Synopsis:       libedit's search doesn work in /bin/sh's vi-mode
>Confidential:   yes
>Severity:       non-critical
>Priority:       low
>Responsible:    bin-bug-people (Utility Bug People)
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Mon Aug 31 14:05:02 1998
>Last-Modified:
>Originator:     Wolfgang Helbig
>Organization:
	
>Release:        NetBSD 1.3.2
>Environment:
	
	System:	NetBSD RVC1 1.3.2
		NetBSD 1.3.2 (RVC2)
		#2: Sat Aug 29 06:03:18 PDT 1998
		helbig@RVC1:/usr/src/sys/arch/i386/compile/RVC2 i386
>Description:
	Commandline search doesn't work, if the vi-mode is turned on
	in bin/sh.
>How-To-Repeat:
	Invoke "/bin/sh -V", enter some commands, hit the escape key
	to enter vi-mode and search for the first entered command.
	(/firstcommand). This will *not* put the first command on the
	commandline.
>Fix:
	Below is a patch to lib/libedit/search.c: sizeof pointer-to-something
	was changed to the size of something, which can be quite different.
	This patch was submitted by myself to FreeBSD's libedit some time
	ago and comitted by msmith on 1997/07/14. (Revision 1.6 of
	lib/libedit/search.c, which happens to be the current revision)
--- search.c.orig	Sun Aug 30 21:21:57 1998
+++ search.c	Sat Jun 13 20:27:17 1998
@@ -471,8 +471,7 @@
 	    (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);
+	    (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++] = '*';
@@ -486,8 +485,7 @@
 	tmpbuf[tmplen++] = '*';
 #endif
 	tmpbuf[tmplen] = '\0';
-	(void)strncpy(el->el_search.patbuf, tmpbuf,
-	    sizeof(el->el_search.patbuf) - 1);
+	(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 */
>Audit-Trail:
>Unformatted: