Bug 182463 - vi(1): vi core dumps on exit with a specific vi.exrc [regression]
Summary: vi(1): vi core dumps on exit with a specific vi.exrc [regression]
Status: Closed FIXED
Alias: None
Product: Base System
Classification: Unclassified
Component: bin (show other bugs)
Version: Unspecified
Hardware: Any Any
: Normal Affects Only Me
Assignee: freebsd-bugs (Nobody)
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2013-09-28 17:30 UTC by Martin Birgmeier
Modified: 2015-07-08 17:37 UTC (History)
1 user (show)

See Also:


Attachments
file.shar (3.40 KB, text/plain)
2013-09-28 17:30 UTC, Martin Birgmeier
no flags Details
vi.exrc.uu (4.19 KB, text/x-uuencode)
2013-09-28 18:04 UTC, Martin Birgmeier
no flags Details
vi.exrc.txt (4.19 KB, text/plain; charset=ISO-8859-1)
2013-09-28 18:39 UTC, Martin Birgmeier
no flags Details
vi.exrc.txt (4.47 KB, text/plain; charset=ISO-8859-1)
2013-09-28 18:54 UTC, Martin Birgmeier
no flags Details
0001-Fix-SLIST-surgery.patch (898 bytes, patch)
2013-12-07 16:10 UTC, wjenkner
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Martin Birgmeier 2013-09-28 17:30:00 UTC
Since my last update of the FreeBSD head branch (from r253885 to r255890), vi crashes on exit (SIGBUS) if I have the attached vi.exrc in /etc (/etc/vi.exrc).

Fix: Patch attached with submission follows:
How-To-Repeat: Install the attached file into /etc/vi.exrc, start vi and observe it crashing on exit.
Comment 1 Martin Birgmeier 2013-09-28 18:04:00 UTC
The shar is mangled, attached a uuencoded version.
Comment 2 Martin Birgmeier 2013-09-28 18:39:44 UTC
Another try, renaming the uuencoded file...
Comment 3 Martin Birgmeier 2013-09-28 18:54:45 UTC
Whoever told gnats to expand uuencoded files?

Try again, prepending "XXX "
Comment 4 wjenkner 2013-12-07 16:10:58 UTC
I can reproduce the bug on 10.0-BETA3 when setting MALLOC_CONF=junk:true
in vi's environment.  However, even with the default malloc options, vi
crashes reliably when the terminal window where it runs is resized
(which makes vi rather unusable with a dwm-style tiling window manager).

Both crashes seem to be due to an oversight in commit 68ca13 in the
upstream nvi2 repo

https://github.com/lichray/nvi2

The (hopefully) attached patch fixes this.  It can be applied with
`patch -p1 <...' in /usr/src/contrib/nvi and vi can then be rebuilt from
/usr/src/usr.bin/vi.

Note that NetBSD, OpenBSD and skimo's nvi don't use SLIST, but DFly does
and so has probably the same bug.

I have Bcc'ed lichray in order not to expose his address here.
Comment 5 lichray 2013-12-07 19:23:17 UTC
On Sat, Dec 7, 2013 at 11:10 AM, Wolfgang Jenkner <wjenkner@inode.at> wrote:
> I can reproduce the bug on 10.0-BETA3 when setting MALLOC_CONF=junk:true
> in vi's environment.  However, even with the default malloc options, vi
> crashes reliably when the terminal window where it runs is resized
> (which makes vi rather unusable with a dwm-style tiling window manager).

I see the problem here, I blindly remove the head of list,
but it's possible to have an multi char mapping before
a single char mapping in .exrc.

I'll fix this bug soon.

The patch is correct.

-- 
Zhihao Yuan, ID lichray
The best way to predict the future is to invent it.
___________________________________________________
4BSD -- http://4bsd.biz/
Comment 6 zy 2013-12-07 23:23:07 UTC
OK, I confirmed that the patch is correct and committed in the change:

  https://github.com/lichray/nvi2/commit/c80f493b0382d3cee115a98f2bc89631c0d06e0f

-- 
Zhihao Yuan, ID lichray
The best way to predict the future is to invent it.
___________________________________________________
4BSD -- http://4bsd.biz/
Comment 7 dfilter service freebsd_committer freebsd_triage 2013-12-08 00:08:11 UTC
Author: peter
Date: Sun Dec  8 00:08:03 2013
New Revision: 259088
URL: http://svnweb.freebsd.org/changeset/base/259088

Log:
  Vendor import nvi-2.1.2-c80f493b038 a multikey mapping fix
  
  PR:		bin/182463

Modified:
  head/contrib/nvi/cl/cl_term.c
  head/contrib/nvi/common/key.c
  head/contrib/nvi/common/key.h
Directory Properties:
  head/contrib/nvi/   (props changed)

Modified: head/contrib/nvi/cl/cl_term.c
==============================================================================
--- head/contrib/nvi/cl/cl_term.c	Sun Dec  8 00:05:31 2013	(r259087)
+++ head/contrib/nvi/cl/cl_term.c	Sun Dec  8 00:08:03 2013	(r259088)
@@ -10,7 +10,7 @@
 #include "config.h"
 
 #ifndef lint
-static const char sccsid[] = "$Id: cl_term.c,v 10.33 2012/04/21 23:51:46 zy Exp $";
+static const char sccsid[] = "$Id: cl_term.c,v 10.34 2013/12/07 16:21:14 wjenkner Exp $";
 #endif /* not lint */
 
 #include <sys/types.h>
@@ -187,14 +187,18 @@ cl_term_init(SCR *sp)
 int
 cl_term_end(GS *gp)
 {
-	SEQ *qp, *nqp;
+	SEQ *qp, *nqp, *pre_qp = NULL;
 
 	/* Delete screen specific mappings. */
 	SLIST_FOREACH_SAFE(qp, gp->seqq, q, nqp)
 		if (F_ISSET(qp, SEQ_SCREEN)) {
-			SLIST_REMOVE_HEAD(gp->seqq, q);
+			if (qp == SLIST_FIRST(gp->seqq))
+				SLIST_REMOVE_HEAD(gp->seqq, q);
+			else
+				SLIST_REMOVE_AFTER(pre_qp, q);
 			(void)seq_free(qp);
-		}
+		} else
+			pre_qp = qp;
 	return (0);
 }
 

Modified: head/contrib/nvi/common/key.c
==============================================================================
--- head/contrib/nvi/common/key.c	Sun Dec  8 00:05:31 2013	(r259087)
+++ head/contrib/nvi/common/key.c	Sun Dec  8 00:08:03 2013	(r259088)
@@ -10,7 +10,7 @@
 #include "config.h"
 
 #ifndef lint
-static const char sccsid[] = "$Id: key.c,v 10.53 2013/03/11 01:20:53 yamt Exp $";
+static const char sccsid[] = "$Id: key.c,v 10.54 2013/11/13 12:15:27 zy Exp $";
 #endif /* not lint */
 
 #include <sys/types.h>
@@ -272,7 +272,7 @@ v_key_name(
 	 * The code prints non-printable wide characters in 4 or 5 digits
 	 * Unicode escape sequences, so only supports plane 0 to 15.
 	 */
-	if (ISPRINT(ach))
+	if (CAN_PRINT(sp, ach))
 		goto done;
 nopr:	if (iscntrl(ch) && (ch < 0x20 || ch == 0x7f)) {
 		sp->cname[0] = '^';

Modified: head/contrib/nvi/common/key.h
==============================================================================
--- head/contrib/nvi/common/key.h	Sun Dec  8 00:05:31 2013	(r259087)
+++ head/contrib/nvi/common/key.h	Sun Dec  8 00:08:03 2013	(r259088)
@@ -6,7 +6,7 @@
  *
  * See the LICENSE file for redistribution information.
  *
- *	$Id: key.h,v 10.55 2012/10/07 01:31:17 zy Exp $
+ *	$Id: key.h,v 10.56 2013/11/13 12:15:27 zy Exp $
  */
 
 #include "multibyte.h"
@@ -23,8 +23,9 @@
 #define INPUT2INT5(sp,cw,n,nlen,w,wlen)					    \
     sp->conv.input2int(sp, n, nlen, &(cw), &wlen, &w)
 #define CONST
+#define INTISWIDE(c)        (wctob(c) == EOF)
 #define CHAR_WIDTH(sp, ch)  wcwidth(ch)
-#define INTISWIDE(c)	(wctob(c) == EOF)
+#define CAN_PRINT(sp, ch)   (CHAR_WIDTH(sp, ch) > 0)
 #else
 #define FILE2INT5(sp,buf,n,nlen,w,wlen) \
     (w = n, wlen = nlen, 0)
@@ -36,9 +37,10 @@
     (n = w, nlen = wlen, 0)
 #define INPUT2INT5(sp,buf,n,nlen,w,wlen) \
     (w = n, wlen = nlen, 0)
-#define CONST const
-#define INTISWIDE(c)	    0
+#define CONST               const
+#define INTISWIDE(c)        0
 #define CHAR_WIDTH(sp, ch)  1
+#define CAN_PRINT(sp, ch)   isprint(ch)
 #endif
 #define FILE2INT(sp,n,nlen,w,wlen)					    \
     FILE2INT5(sp,sp->cw,n,nlen,w,wlen)
_______________________________________________
svn-src-all@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "svn-src-all-unsubscribe@freebsd.org"
Comment 8 Martin Birgmeier 2014-08-15 07:40:01 UTC
This PR should be closed as it has been resolved.

-- Martin
Comment 9 commit-hook freebsd_committer freebsd_triage 2014-08-15 19:07:26 UTC
A commit references this bug:

Author: emaste
Date: Fri Aug 15 19:07:00 UTC 2014
New revision: 270026
URL: http://svnweb.freebsd.org/changeset/base/270026

Log:
  MFC r259088: Vendor import nvi-2.1.2-c80f493b038 a multikey mapping fix

  PR:	bin/182463

Changes:
_U  stable/10/
  stable/10/contrib/nvi/cl/cl_term.c
  stable/10/contrib/nvi/common/key.c
  stable/10/contrib/nvi/common/key.h
Comment 10 Ed Maste freebsd_committer freebsd_triage 2014-08-15 19:07:35 UTC
MFC'd to 10 in r270026
Comment 11 Glen Barber freebsd_committer freebsd_triage 2015-07-08 17:37:21 UTC
Close PRs that have a corresponding commit to resolve the issue.