Module Name:    src
Committed By:   rin
Date:           Mon Dec 19 17:51:40 UTC 2016

Modified Files:
        src/external/bsd/nvi/dist/ex: ex_script.c

Log Message:
improve logic related to sh_prompt:
- sscr_insert(): sh_prompt should be compared with t, not p
- replace strnstr(3) with memcmp(3)
now, nvi is free from strnstr(3); it can be safely pulled-up into netbsd-7


To generate a diff of this commit:
cvs rdiff -u -r1.6 -r1.7 src/external/bsd/nvi/dist/ex/ex_script.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/external/bsd/nvi/dist/ex/ex_script.c
diff -u src/external/bsd/nvi/dist/ex/ex_script.c:1.6 src/external/bsd/nvi/dist/ex/ex_script.c:1.7
--- src/external/bsd/nvi/dist/ex/ex_script.c:1.6	Sun Nov 29 17:09:33 2015
+++ src/external/bsd/nvi/dist/ex/ex_script.c	Mon Dec 19 17:51:40 2016
@@ -1,4 +1,4 @@
-/*	$NetBSD: ex_script.c,v 1.6 2015/11/29 17:09:33 christos Exp $ */
+/*	$NetBSD: ex_script.c,v 1.7 2016/12/19 17:51:40 rin Exp $ */
 /*-
  * Copyright (c) 1992, 1993, 1994
  *	The Regents of the University of California.  All rights reserved.
@@ -19,7 +19,7 @@
 static const char sccsid[] = "Id: ex_script.c,v 10.38 2001/06/25 15:19:19 skimo Exp  (Berkeley) Date: 2001/06/25 15:19:19 ";
 #endif /* not lint */
 #else
-__RCSID("$NetBSD: ex_script.c,v 1.6 2015/11/29 17:09:33 christos Exp $");
+__RCSID("$NetBSD: ex_script.c,v 1.7 2016/12/19 17:51:40 rin Exp $");
 #endif
 
 #include <sys/types.h>
@@ -274,7 +274,7 @@ sscr_exec(SCR *sp, db_recno_t lno)
 		return (1);
 	INT2CHAR(sp, ip, ilen, p, last_len);
 	if (last_len == sc->sh_prompt_len &&
-	    strnstr(p, sc->sh_prompt, last_len) == p) {
+	    memcmp(p, sc->sh_prompt, last_len) == 0) {
 		matchprompt = 1;
 		GET_SPACE_RETC(sp, bp, blen, last_len + 128);
 		memmove(bp, p, last_len);
@@ -294,7 +294,8 @@ sscr_exec(SCR *sp, db_recno_t lno)
 	INT2CHAR(sp, ip, ilen, p, len);
 
 	/* Delete any prompt. */
-	if (strnstr(p, sc->sh_prompt, len) == p) {
+	if (len >= sc->sh_prompt_len &&
+	    memcmp(p, sc->sh_prompt, sc->sh_prompt_len) == 0) {
 		len -= sc->sh_prompt_len;
 		if (len == 0) {
 empty:			msgq(sp, M_BERR, "151|No command to execute");
@@ -473,7 +474,7 @@ more:	switch (nr = read(sc->sh_master, e
 	 */
 	len = p - t;
 	if (sc->sh_prompt == NULL || len != sc->sh_prompt_len ||
-	    strnstr(p, sc->sh_prompt, len) == NULL) {
+	    memcmp(t, sc->sh_prompt, len) != 0) {
 		tv.tv_sec = 0;
 		tv.tv_usec = 100000;
 		FD_ZERO(&rdfd);
@@ -509,7 +510,7 @@ more:	switch (nr = read(sc->sh_master, e
 /*
  * sscr_setprompt --
  *
- * Set the prompt to the last line we got from the shell.
+ * Set the prompt in external ("char") encoding.
  *
  */
 static int

Reply via email to