git: 5ac4f1e50257 - main - editors/nvi2: Fix core dump when tags file pattern has a trailing '\'

From: Craig Leres <leres_at_FreeBSD.org>
Date: Thu, 03 Nov 2022 06:41:59 UTC
The branch main has been updated by leres:

URL: https://cgit.FreeBSD.org/ports/commit/?id=5ac4f1e502572cd1e2e8678600a56b3894af2e95

commit 5ac4f1e502572cd1e2e8678600a56b3894af2e95
Author:     Craig Leres <leres@FreeBSD.org>
AuthorDate: 2022-11-03 06:41:34 +0000
Commit:     Craig Leres <leres@FreeBSD.org>
CommitDate: 2022-11-03 06:41:34 +0000

    editors/nvi2: Fix core dump when tags file pattern has a trailing '\'
    
    If you create a tags file of a macro that ends with a '\' and tag
    for it, vi dumps core. For example:
    
        zinc 76 % cat test.h
        #define LATIN2PLAIN(ch) (((u_char)ch) >= 0x80 ? \
           pgm_read_byte_far(pgm_get_far_address(latin2plain) + \
           (((u_char)ch) - 0x80)) : (isprint(ch) ? (ch) : '_'))
        zinc 77 % ctags test.h
        zinc 78 % vi -t LATIN2PLAIN
        Segmentation fault
    
    The problem is that the loop variable is unsigned (size_t) and it
    gets decremented twice: 1 -> 0 -> 4294967295
    
    Apply the upstream patch to solve this:
    
        https://github.com/lichray/nvi2/pull/111
---
 editors/nvi2/Makefile                   |  1 +
 editors/nvi2/files/patch-ex_ex__subst.c | 12 ++++++++++++
 2 files changed, 13 insertions(+)

diff --git a/editors/nvi2/Makefile b/editors/nvi2/Makefile
index d9f955eb7d57..dfa27945a477 100644
--- a/editors/nvi2/Makefile
+++ b/editors/nvi2/Makefile
@@ -1,6 +1,7 @@
 PORTNAME=	nvi2
 PORTVERSION=	2.2.0
 DISTVERSIONPREFIX=	v
+PORTREVISION=	1
 CATEGORIES=	editors
 
 MAINTAINER=	leres@FreeBSD.org
diff --git a/editors/nvi2/files/patch-ex_ex__subst.c b/editors/nvi2/files/patch-ex_ex__subst.c
new file mode 100644
index 000000000000..6ff00423160c
--- /dev/null
+++ b/editors/nvi2/files/patch-ex_ex__subst.c
@@ -0,0 +1,12 @@
+--- ex/ex_subst.c.orig	2020-08-01 22:27:51 UTC
++++ ex/ex_subst.c
+@@ -1194,7 +1194,8 @@ re_tag_conv(SCR *sp, CHAR_T **ptrnp, size_t *plenp, in
+ 	for (; len > 0; --len) {
+ 		if (p[0] == '\\' && (p[1] == '/' || p[1] == '?')) {
+ 			++p;
+-			--len;
++			if (len > 1)
++				--len;
+ 		} else if (STRCHR(L("^.[]$*"), p[0]))
+ 			*t++ = '\\';
+ 		*t++ = *p++;