Module Name:    src
Committed By:   rin
Date:           Wed Nov 22 12:47:30 UTC 2017

Modified Files:
        src/external/bsd/nvi/dist/common: delete.c
        src/external/bsd/nvi/dist/vi: v_sentence.c

Log Message:
Fix segmentation fault in corner case of backward sentence deletion,
taken from nvi2 (and Debian Bug report #193498):
https://github.com/lichray/nvi2/commit/e84d40ec20b257edad6810062204366ff0ddff58
https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=193498


To generate a diff of this commit:
cvs rdiff -u -r1.3 -r1.4 src/external/bsd/nvi/dist/common/delete.c
cvs rdiff -u -r1.3 -r1.4 src/external/bsd/nvi/dist/vi/v_sentence.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/common/delete.c
diff -u src/external/bsd/nvi/dist/common/delete.c:1.3 src/external/bsd/nvi/dist/common/delete.c:1.4
--- src/external/bsd/nvi/dist/common/delete.c:1.3	Sun Jan 26 21:43:45 2014
+++ src/external/bsd/nvi/dist/common/delete.c	Wed Nov 22 12:47:30 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: delete.c,v 1.3 2014/01/26 21:43:45 christos Exp $ */
+/*	$NetBSD: delete.c,v 1.4 2017/11/22 12:47:30 rin Exp $ */
 /*-
  * Copyright (c) 1992, 1993, 1994
  *	The Regents of the University of California.  All rights reserved.
@@ -16,7 +16,7 @@
 static const char sccsid[] = "Id: delete.c,v 10.17 2001/06/25 15:19:09 skimo Exp  (Berkeley) Date: 2001/06/25 15:19:09 ";
 #endif /* not lint */
 #else
-__RCSID("$NetBSD: delete.c,v 1.3 2014/01/26 21:43:45 christos Exp $");
+__RCSID("$NetBSD: delete.c,v 1.4 2017/11/22 12:47:30 rin Exp $");
 #endif
 
 #include <sys/types.h>
@@ -95,14 +95,16 @@ del(SCR *sp, MARK *fm, MARK *tm, int lmo
 	if (tm->lno == fm->lno) {
 		if (db_get(sp, fm->lno, DBG_FATAL, &p, &len))
 			return (1);
-		GET_SPACE_RETW(sp, bp, blen, len);
-		if (fm->cno != 0)
-			MEMCPYW(bp, p, fm->cno);
-		MEMCPYW(bp + fm->cno, p + (tm->cno + 1), 
-			len - (tm->cno + 1));
-		if (db_set(sp, fm->lno,
-		    bp, len - ((tm->cno - fm->cno) + 1)))
-			goto err;
+		if (len != 0) {
+			GET_SPACE_RETW(sp, bp, blen, len);
+			if (fm->cno != 0)
+				MEMCPYW(bp, p, fm->cno);
+			MEMCPYW(bp + fm->cno, p + (tm->cno + 1), 
+				len - (tm->cno + 1));
+			if (db_set(sp, fm->lno,
+			    bp, len - ((tm->cno - fm->cno) + 1)))
+				goto err;
+		}
 		goto done;
 	}
 

Index: src/external/bsd/nvi/dist/vi/v_sentence.c
diff -u src/external/bsd/nvi/dist/vi/v_sentence.c:1.3 src/external/bsd/nvi/dist/vi/v_sentence.c:1.4
--- src/external/bsd/nvi/dist/vi/v_sentence.c:1.3	Sun Jan 26 21:43:45 2014
+++ src/external/bsd/nvi/dist/vi/v_sentence.c	Wed Nov 22 12:47:30 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: v_sentence.c,v 1.3 2014/01/26 21:43:45 christos Exp $ */
+/*	$NetBSD: v_sentence.c,v 1.4 2017/11/22 12:47:30 rin Exp $ */
 /*-
  * Copyright (c) 1992, 1993, 1994
  *	The Regents of the University of California.  All rights reserved.
@@ -16,7 +16,7 @@
 static const char sccsid[] = "Id: v_sentence.c,v 10.9 2001/06/25 15:19:35 skimo Exp  (Berkeley) Date: 2001/06/25 15:19:35 ";
 #endif /* not lint */
 #else
-__RCSID("$NetBSD: v_sentence.c,v 1.3 2014/01/26 21:43:45 christos Exp $");
+__RCSID("$NetBSD: v_sentence.c,v 1.4 2017/11/22 12:47:30 rin Exp $");
 #endif
 
 #include <sys/types.h>
@@ -297,7 +297,7 @@ ret:			slno = cs.cs_lno;
 			 * we can end up where we started.  Fix it.
 			 */
 			if (vp->m_start.lno != cs.cs_lno ||
-			    vp->m_start.cno != cs.cs_cno)
+			    vp->m_start.cno > cs.cs_cno)
 				goto okret;
 
 			/*

Reply via email to