From nobody@FreeBSD.ORG  Thu Sep  7 02:50:35 2000
Return-Path: <nobody@FreeBSD.ORG>
Received: by hub.freebsd.org (Postfix, from userid 32767)
	id E8B8037B422; Thu,  7 Sep 2000 02:50:34 -0700 (PDT)
Message-Id: <20000907095034.E8B8037B422@hub.freebsd.org>
Date: Thu,  7 Sep 2000 02:50:34 -0700 (PDT)
From: lfrigault@teaser.fr
Sender: nobody@FreeBSD.ORG
To: freebsd-gnats-submit@FreeBSD.org
Subject: vi silently corrupt open file on SIGINT when entering :wq in command mode
X-Send-Pr-Version: www-1.0

>Number:         21089
>Category:       bin
>Synopsis:       [patch] vi(1) silently corrupts open file on SIGINT when entering :wq in command mode
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    jh
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Thu Sep 07 03:00:01 PDT 2000
>Closed-Date:    Fri Sep 10 04:56:08 UTC 2010
>Last-Modified:  Fri Sep 10 04:56:08 UTC 2010
>Originator:     Laurent Frigault
>Release:        4.1-STABLE
>Organization:
France Teaser
>Environment:
FreeBSD becile.teaser.fr 4.1-STABLE FreeBSD 4.1-STABLE #12: Mon Aug 21 20:26:08 CEST 2000     lfrigault@becile.teaser.fr:/usr/src/sys/compile/BECILE  i386
>Description:
The version of vi that come with FreeBSD 4.1 can silently corrupt files
on SIGINT when typing :wq in command mode
>How-To-Repeat:
1/ open a file (~70K)
2/ in command mode enter :wq without validating with return
3/ in an other term, killall -INT vi
4/ vi terminate silently and the file is corrupted.
>Fix:


>Release-Note:
>Audit-Trail:

From: Sheldon Hearn <sheldonh@uunet.co.za>
To: lfrigault@teaser.fr
Cc: freebsd-gnats-submit@freebsd.org
Subject: Re: misc/21089: vi silently corrupt open file on SIGINT when entering :wq in command mode 
Date: Fri, 08 Sep 2000 15:33:40 +0200

 On Thu, 07 Sep 2000 02:50:34 MST, lfrigault@teaser.fr wrote:
 
 > >Number:         21089
 > >Category:       misc
 > >Synopsis:       vi silently corrupt open file on SIGINT when entering :wq in
 command mode
 
 As a datapoint, I don't see this behaviour in the development branch.
 In fact, SIGINT doesn't even kill vi when it's in command state!  It
 just aborts out of command-state, as expected.
 
 Can anyone else confirm the results reported?
 
 Ciao,
 Sheldon.
 

From: Laurent Frigault <lfrigault@teaser.fr>
To: Sheldon Hearn <sheldonh@uunet.co.za>
Cc: freebsd-gnats-submit@freebsd.org
Subject: Re: misc/21089: vi silently corrupt open file on SIGINT when entering :wq in command mode
Date: Fri, 8 Sep 2000 17:32:24 +0200

 On Fri, Sep 08, 2000 at 03:33:40PM +0200, Sheldon Hearn wrote:
 > > >Number:         21089
 > > >Category:       misc
 > > >Synopsis:       vi silently corrupt open file on SIGINT when entering :wq in
 > command mode
 > 
 > As a datapoint, I don't see this behaviour in the development branch.
 > In fact, SIGINT doesn't even kill vi when it's in command state!  It
 > just aborts out of command-state, as expected.
 > 
 > Can anyone else confirm the results reported?
 
 If you enter <ESC>: SIGINT has no effect
 If you enter <ESC>:w The file is corrupted on SIGINT and you have a message :
 =================================
 +=+=+=+=+=+=+=+
 :w
 Interrupted
 Press any key to continue: 
 =================================
 and the file is save corrupted but you can re-write it with
 <ESC>:wq<ENTER>
 
 If you enter <ESC>:wq The file is save corrupted on SIGINT and vi
 terminate silently
 
 I have reproduced the problem under :
 FreeBSD victor.teaser.fr 5.0-CURRENT FreeBSD 5.0-CURRENT #10: Wed Aug  9 16:34:08 CEST 2000     lwa@victor.teaser.fr:/usr/src/sys/compile/VICTOR i386
 
 Hope, this helps
 
 Laurent
 -- 
 Laurent Frigault | <url:http://www.teaser.fr/~lfrigault>
 

From: Mario Hoerich <lists@MHoerich.de>
To: freebsd-gnats-submit@FreeBSD.org, lfrigault@teaser.fr
Cc:  
Subject: Re: bin/21089: vi silently corrupt open file on SIGINT when entering :wq in command mode
Date: Tue, 8 Feb 2005 01:39:09 +0100

 Hello, 
 
 the bug seems to persist:
 
 $ wc -l article.txt
     1756 article.txt
 
  <vi file, type ':wq', enter killall -INT on different console>
  
 $ wc -l article.txt
       99 article.txt
 
 System: FreeBSD 5.3-STABLE #0: Sat Jan 22 18:58:33 CET 2005, i386
 
 Regards.
 Mario

From: Jaakko Heinonen <jh@saunalahti.fi>
To: bug-followup@FreeBSD.org, lfrigault@teaser.fr
Cc: lists@MHoerich.de
Subject: Re: bin/21089: vi silently corrupt open file on SIGINT when
	entering :wq in command mode
Date: Wed, 6 Feb 2008 08:55:06 +0200

 --qDbXVdCdHGoSgWSk
 Content-Type: text/plain; charset=us-ascii
 Content-Disposition: inline
 
 
 The bug still exists in 7.0-RC1. I believe that the attached patch fixes
 it. Can you confirm?
 
 -- 
 Jaakko
 
 --qDbXVdCdHGoSgWSk
 Content-Type: text/x-diff; charset=us-ascii
 Content-Disposition: attachment; filename="nvi-SIGINT.diff"
 
 Index: ex/ex_quit.c
 ===================================================================
 RCS file: /home/ncvs/src/contrib/nvi/ex/ex_quit.c,v
 retrieving revision 1.1.1.1
 diff -u -r1.1.1.1 ex_quit.c
 --- ex/ex_quit.c	1 Nov 1996 06:45:30 -0000	1.1.1.1
 +++ ex/ex_quit.c	6 Feb 2008 06:45:32 -0000
 @@ -35,6 +35,9 @@
  {
  	int force;
  
 +	if (INTERRUPTED(sp))
 +		return (1);
 +
  	force = FL_ISSET(cmdp->iflags, E_C_FORCE);
  
  	/* Check for file modifications, or more files to edit. */
 Index: ex/ex_write.c
 ===================================================================
 RCS file: /home/ncvs/src/contrib/nvi/ex/ex_write.c,v
 retrieving revision 1.1.1.1
 diff -u -r1.1.1.1 ex_write.c
 --- ex/ex_write.c	1 Nov 1996 06:45:31 -0000	1.1.1.1
 +++ ex/ex_write.c	6 Feb 2008 06:45:32 -0000
 @@ -140,6 +140,9 @@
  	int flags;
  	char *name, *p;
  
 +	if (INTERRUPTED(sp))
 +		return (1);
 +
  	NEEDFILE(sp, cmdp);
  
  	/* All write commands can have an associated '!'. */
 @@ -323,8 +326,6 @@
  		for (; fline <= tline; ++fline, ++lcnt) {
  			/* Caller has to provide any interrupt message. */
  			if ((lcnt + 1) % INTERRUPT_CHECK == 0) {
 -				if (INTERRUPTED(sp))
 -					break;
  				if (!silent) {
  					gp->scr_busy(sp, msg, msg == NULL ?
  					    BUSY_UPDATE : BUSY_ON);
 
 --qDbXVdCdHGoSgWSk--

From: Laurent Frigault <lfrigault@agneau.org>
To: Jaakko Heinonen <jh@saunalahti.fi>
Cc: bug-followup@FreeBSD.org, lists@MHoerich.de
Subject: Re: bin/21089: vi silently corrupt open file on SIGINT when entering :wq in command mode
Date: Wed, 6 Feb 2008 20:58:19 +0100

 On Wed, Feb 06, 2008 at 08:55:06AM +0200, Jaakko Heinonen wrote:
 > 
 > The bug still exists in 7.0-RC1. I believe that the attached patch fixes
 > it. Can you confirm?
 
 Yes. I just apply the patch to 7.0-RC1 and that fixes the problem.
 
 Regards,
 -- 
 Laurent Frigault | <url:http://www.agneau.org/>
State-Changed-From-To: open->analyzed 
State-Changed-By: linimon 
State-Changed-When: Thu Feb 7 05:12:28 UTC 2008 
State-Changed-Why:  
Sumbitter notes that the suggested patch cures the problem. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=21089 

From: Yar Tikhiy <yar@comp.chem.msu.su>
To: Jaakko Heinonen <jh@saunalahti.fi>
Cc: bug-followup@freebsd.org
Subject: Re: bin/21089: vi silently corrupt open file on SIGINT when entering :wq in command mode
Date: Sun, 10 Feb 2008 01:12:44 +0300

 Jaakko,
 
 I think that you looked in the right direction but applied the fix
 at a wrong level.  In fact, we shouldn't put a test for INTERRUPTED(sp)
 into each ex command's implementation.  In ex mode, the call stack
 is as follows:
 
 	main -> editor -> ex -> ex_cmd -> <individual command>
 
 Among the functions, it's ex() that takes care of INTERRUPTED(sp).
 Therefore we should do something similar, too, when ex_cmd() is called
 from vi mode.  In the latter case the call stack looks as follows:
 
 	main -> editor -> vi -> v_ex -> ex_cmd -> <individual command>
 
 So we should be looking at somewhere around v_ex().  But, in fact,
 a similar problem is found in all consumers of v_tcmd(): ^C doesn't
 abort the command being typed, it commits the command instead.  That
 applies both to colon commands and to search commands.  In the case
 of `:w' the problem just gets much worse because interrupted status
 remains set and blows up the command later.
 
 To make things even more complicated, a window resize event behaves
 much like ^C in that it commits the command being typed, which can
 have an unwanted result.
 
 The NetBSD folks seem to have fixed this bug generally in v_ex.c
 and v_text.c, but their fix is hackish, too: they now pretend that
 ^C or a window resize event is the same as <Esc>.
 
 What perhaps is needed is a clear indication from v_txt() to its
 caller that a special event ended text input, so that it can be up
 to the caller to decide how to handle the event.
 
 But for now the ^C bug can be fixed quickly as shown in the attached
 patch.  With the patch applied, ^C will commit neither ex commands
 nor search commands: it'll abort them instead, which makes much more
 sense IMHO.
 
 Yar
 
 Index: vi/v_txt.c
 ===================================================================
 RCS file: /home/ncvs/src/contrib/nvi/vi/v_txt.c,v
 retrieving revision 1.1.1.1
 diff -u -p -r1.1.1.1 v_txt.c
 --- vi/v_txt.c	1 Nov 1996 06:45:33 -0000	1.1.1.1
 +++ vi/v_txt.c	9 Feb 2008 22:06:02 -0000
 @@ -110,6 +110,10 @@ v_tcmd(sp, vp, prompt, flags)
  	sp->lno = vp->m_final.lno;
  	sp->cno = vp->m_final.cno;
  
 +	/* Interrupt aborts the command. */
 +	if (INTERRUPTED(sp))
 +		return (1);
 +
  	return (0);
  }
  

From: Jaakko Heinonen <jh@saunalahti.fi>
To: Yar Tikhiy <yar@comp.chem.msu.su>
Cc: bug-followup@freebsd.org
Subject: Re: bin/21089: vi silently corrupt open file on SIGINT when
	entering :wq in command mode
Date: Tue, 12 Feb 2008 20:02:25 +0200

 --pf9I7BMVVzbSWLtt
 Content-Type: text/plain; charset=us-ascii
 Content-Disposition: inline
 
 
 Hi,
 
 On 2008-02-10, Yar Tikhiy wrote:
 > I think that you looked in the right direction but applied the fix
 > at a wrong level.  In fact, we shouldn't put a test for INTERRUPTED(sp)
 > into each ex command's implementation.
 
 Agreed.
 
 [thanks for good analysis of the problem]
 
 > What perhaps is needed is a clear indication from v_txt() to its
 > caller that a special event ended text input, so that it can be up
 > to the caller to decide how to handle the event.
 
 What do you think about the attached patch? It sets a global state flag
 when a resize event occurs. I am not sure if it's a good way to do it.
 
 > But for now the ^C bug can be fixed quickly as shown in the attached
 > patch.
 
 Looks much better than my original patch.
 
 -- 
 Jaakko
 
 --pf9I7BMVVzbSWLtt
 Content-Type: text/x-diff; charset=us-ascii
 Content-Disposition: attachment; filename="nvi-SIGINT.diff"
 
 Index: common/gs.h
 ===================================================================
 RCS file: /home/ncvs/src/contrib/nvi/common/gs.h,v
 retrieving revision 1.1.1.1
 diff -p -u -r1.1.1.1 gs.h
 --- common/gs.h	1 Nov 1996 06:45:37 -0000	1.1.1.1
 +++ common/gs.h	12 Feb 2008 17:55:35 -0000
 @@ -144,6 +144,7 @@ struct _gs {
  #define	G_SNAPSHOT	0x0040		/* Always snapshot files. */
  #define	G_SRESTART	0x0080		/* Screen restarted. */
  #define	G_TMP_INUSE	0x0100		/* Temporary buffer in use. */
 +#define	G_RESIZE	0x0200		/* Resize requested. */
  	u_int32_t flags;
  
  	/* Screen interface functions. */
 Index: common/key.c
 ===================================================================
 RCS file: /home/ncvs/src/contrib/nvi/common/key.c,v
 retrieving revision 1.1.1.1
 diff -p -u -r1.1.1.1 key.c
 --- common/key.c	1 Nov 1996 06:45:37 -0000	1.1.1.1
 +++ common/key.c	12 Feb 2008 17:55:35 -0000
 @@ -591,6 +591,10 @@ loop:		if (gp->scr_event(sp, argp,
  			if (LF_ISSET(EC_INTERRUPT))
  				return (0);
  			goto append;
 +		case E_WRESIZE:
 +			/* Set the global resize flag. */
 +			F_SET(sp->gp, G_RESIZE);
 +			goto append;
  		default:
  append:			if (v_event_append(sp, argp))
  				return (1);
 Index: vi/v_txt.c
 ===================================================================
 RCS file: /home/ncvs/src/contrib/nvi/vi/v_txt.c,v
 retrieving revision 1.1.1.1
 diff -p -u -r1.1.1.1 v_txt.c
 --- vi/v_txt.c	1 Nov 1996 06:45:33 -0000	1.1.1.1
 +++ vi/v_txt.c	12 Feb 2008 17:55:36 -0000
 @@ -92,6 +92,8 @@ v_tcmd(sp, vp, prompt, flags)
  	if (O_ISSET(sp, O_TTYWERASE))
  		LF_SET(TXT_TTYWERASE);
  
 +	F_CLR(sp->gp, G_RESIZE);
 +
  	/* Do the input thing. */
  	if (v_txt(sp, vp, NULL, NULL, 0, prompt, 0, 1, flags))
  		return (1);
 @@ -109,6 +111,10 @@ v_tcmd(sp, vp, prompt, flags)
  	/* Set the cursor to the resulting position. */
  	sp->lno = vp->m_final.lno;
  	sp->cno = vp->m_final.cno;
 +
 +	/* Abort the command on interrupt or window resize. */
 +	if (INTERRUPTED(sp) || F_ISSET(sp->gp, G_RESIZE))
 +		return (1);
  
  	return (0);
  }
 
 --pf9I7BMVVzbSWLtt--

From: Yar Tikhiy <yar@comp.chem.msu.su>
To: Jaakko Heinonen <jh@saunalahti.fi>
Cc: bug-followup@freebsd.org
Subject: Re: bin/21089: vi silently corrupt open file on SIGINT when entering :wq in command mode
Date: Fri, 15 Feb 2008 14:14:39 +0300

 On Tue, Feb 12, 2008 at 08:02:25PM +0200, Jaakko Heinonen wrote:
 > 
 > On 2008-02-10, Yar Tikhiy wrote:
 > > I think that you looked in the right direction but applied the fix
 > > at a wrong level.  In fact, we shouldn't put a test for INTERRUPTED(sp)
 > > into each ex command's implementation.
 > 
 > Agreed.
 > 
 > [thanks for good analysis of the problem]
 > 
 > > What perhaps is needed is a clear indication from v_txt() to its
 > > caller that a special event ended text input, so that it can be up
 > > to the caller to decide how to handle the event.
 > 
 > What do you think about the attached patch? It sets a global state flag
 > when a resize event occurs. I am not sure if it's a good way to do it.
 
 Well, on the one hand, it's exactly the way interrupt events are
 handled by nvi now.  But, on the other hand, using a global state
 flag has a remarkable downside:  We'll have to remember to clear
 it in each code path where it can be set.  Otherwise problems similar
 to this one will be likely to arise.
 
 Upon a second thought, I'd rather follow the NetBSD way of dealing
 with this issue.  Their way was hackish not for nothing: it had to
 deal with such complex cases of nvi text input as file name completion
 and former input replay.
 
 As a general remark, the NetBSD folks have invested a considerable
 effort in fixing nvi bugs, and we may want to investigate if it would
 be possible to borrow their patches and apply them to our tree.
 
 -- 
 Yar

From: Jaakko Heinonen <jh@saunalahti.fi>
To: Yar Tikhiy <yar@comp.chem.msu.su>
Cc: bug-followup@freebsd.org
Subject: Re: bin/21089: vi silently corrupt open file on SIGINT when
	entering :wq in command mode
Date: Thu, 21 Feb 2008 15:23:34 +0200

 --ew6BAiZeqk4r7MaW
 Content-Type: text/plain; charset=us-ascii
 Content-Disposition: inline
 
 
 Hi,
 
 On 2008-02-15, Yar Tikhiy wrote:
 > Upon a second thought, I'd rather follow the NetBSD way of dealing
 > with this issue.  Their way was hackish not for nothing: it had to
 > deal with such complex cases of nvi text input as file name completion
 > and former input replay.
 
 I have obtained a patch series from NetBSD to fix the ^C and SIGWINCH
 problems. The series contains also all other NetBSD bug fixes for v_txt.c
 excluding fixes for compile warnings. Also OpeBSD seems to use the same
 ^C fix.
 
 I have attached the patches including the original NetBSD cvs log
 messages to this mail.
 
 -- 
 Jaakko
 
 --ew6BAiZeqk4r7MaW
 Content-Type: text/x-diff; charset=us-ascii
 Content-Disposition: attachment; filename="nvi-netbsd-v_ex.c-1.diff"
 
 Obtained from:	NetBSD
 
 date: 2005/09/06 21:21:25;  author: aymeric;  state: Exp;  lines: +6 -2
 when reading an ex command within visual mode with v_tcmd(), check that
 the termination value of v_tcmd() is alright. Abort the command otherwise.
 Until the next commit in vi/v_txt.c, this is a noop.
 
 diff -u -r1.11 -r1.12
 --- v_ex.c	9 Apr 2002 01:47:35 -0000	1.11
 +++ v_ex.c	6 Sep 2005 21:21:25 -0000	1.12
 @@ -428,6 +428,10 @@ v_ex(sp, vp)
  			if (tp->term == TERM_BS)
  				break;
  
 +			/* If the user changed their mind, return. */
 +			if (tp->term != TERM_OK)
 +				break;
 +
  			/* Log the command. */
  			if (O_STR(sp, O_CEDIT) != NULL && v_ecl_log(sp, tp))
  				return (1);
 
 --ew6BAiZeqk4r7MaW
 Content-Type: text/x-diff; charset=us-ascii
 Content-Disposition: attachment; filename="nvi-netbsd-v_txt.c-1.diff"
 
 Obtained from:	NetBSD
 
 date: 2005/09/06 21:30:36;  author: aymeric;  state: Exp;  lines: +21 -10
 Finally handle ^C the correct way. This indeed requires to separate the case
 of text-recording input (usually text in insert mode) from the other cases
 (e.g. ex command input). If recording, morph to escape key so that the input
 is correctly finished for a potential replay; if not, simply bail out and
 notify that something wrong occurs. Callers will cope.
 The previous fix could make ^C sometimes produce a file completion
 or a command edition, depending on the settings of the user.
 I think this is the correct fix for since closed PR bin/11544 by pooka@. ;-)
 ----------------------------
 date: 2001/04/30 21:34:12;  author: aymeric;  state: Exp;  lines: +20 -13
 Now, ^C behaves just like <ESC> (but for the ``Interrupt'' message).
 It is consistent with what Solaris' vi and vim do.
 This addresses PR #11544 by pooka.
 
 Index: v_txt.c
 ===================================================================
 RCS file: /home/ncvs/src/contrib/nvi/vi/v_txt.c,v
 retrieving revision 1.1.1.1
 diff -p -u -r1.1.1.1 v_txt.c
 --- v_txt.c	1 Nov 1996 06:45:33 -0000	1.1.1.1
 +++ v_txt.c	18 Feb 2008 19:16:07 -0000
 @@ -510,15 +510,6 @@ next:	if (v_event_get(sp, evp, 0, ec_fla
  	case E_EOF:
  		F_SET(sp, SC_EXIT_FORCE);
  		return (1);
 -	case E_INTERRUPT:
 -		/*
 -		 * !!!
 -		 * Historically, <interrupt> exited the user from text input
 -		 * mode or cancelled a colon command, and returned to command
 -		 * mode.  It also beeped the terminal, but that seems a bit
 -		 * excessive.
 -		 */
 -		goto k_escape;
  	case E_REPAINT:
  		if (vs_repaint(sp, &ev))
  			return (1);
 @@ -526,10 +517,37 @@ next:	if (v_event_get(sp, evp, 0, ec_fla
  	case E_WRESIZE:
  		/* <resize> interrupts the input mode. */
  		v_emsg(sp, NULL, VIM_WRESIZE);
 -		goto k_escape;
 +	/* FALLTHROUGH */
  	default:
 -		v_event_err(sp, evp);
 -		goto k_escape;
 +		if (evp->e_event != E_INTERRUPT && evp->e_event != E_WRESIZE)
 +			v_event_err(sp, evp);
 +		/*
 +		 * !!!
 +		 * Historically, <interrupt> exited the user from text input
 +		 * mode or cancelled a colon command, and returned to command
 +		 * mode.  It also beeped the terminal, but that seems a bit
 +		 * excessive.
 +		 */
 +		/*
 +		 * If we are recording, morph into <escape> key so that
 +		 * we can repeat the command safely: there is no way to
 +		 * invalidate the repetition of an instance of a command,
 +		 * which would be the alternative possibility.
 +		 * If we are not recording (most likely on the command line),
 +		 * simply discard the input and return to command mode
 +		 * so that an INTERRUPT doesn't become for example a file
 +		 * completion request. -aymeric
 +		 */
 +		if (LF_ISSET(TXT_RECORD)) {
 +		    evp->e_event = E_CHARACTER;
 +		    evp->e_c = 033;
 +		    evp->e_flags = 0;
 +		    evp->e_value = K_ESCAPE;
 +		    break;
 +		} else {
 +		    tp->term = TERM_ESC;
 +		    goto k_escape;
 +		}
  	}
  
  	/*
 
 --ew6BAiZeqk4r7MaW
 Content-Type: text/x-diff; charset=us-ascii
 Content-Disposition: attachment; filename="nvi-netbsd-v_txt.c-2.diff"
 
 Obtained from: NetBSD
 
 date: 2001/08/20 21:44:57;  author: aymeric;  state: Exp;  lines: +2 -2
 Fix a bug present in nvi 1.79 where ^@ wouldn't behave as expected when
 reading an ex command from vi.
 
 diff -p -u -r1.5 -r1.6
 --- v_txt.c	1 May 2001 16:46:12 -0000	1.5
 +++ v_txt.c	20 Aug 2001 21:44:57 -0000	1.6
 @@ -557,7 +557,7 @@ next:	if (v_event_get(sp, evp, 0, ec_fla
  	 * This was not documented as far as I know, and is a great test of vi
  	 * clones.
  	 */
 -	if (rcol == 0 && !LF_ISSET(TXT_REPLAY) && evp->e_c == '\0') {
 +	if (LF_ISSET(TXT_RECORD) && rcol == 0 && evp->e_c == '\0') {
  		if (vip->rep == NULL)
  			goto done;
  
 
 --ew6BAiZeqk4r7MaW
 Content-Type: text/x-diff; charset=us-ascii
 Content-Disposition: attachment; filename="nvi-netbsd-v_txt.c-3.diff"
 
 Obtained from:	NetBSD
 
 date: 2003/06/06 08:06:47;  author: aymeric;  state: Exp;  lines: +3 -2
 branches:  1.11.4;
 When an error occurs in v_txt(), leave input mode too.
 Otherwise, (among other things) db_get() thinks it can re-use the TEXT buffers
 when it's not true, leading to a crash because that TEXT buffer will be
 released just before it is actually used to create a new one.
 This fixes PR#21797.
 
 diff -p -u -r1.10 -r1.11
 --- v_txt.c	6 Jan 2003 20:30:41 -0000	1.10
 +++ v_txt.c	6 Jun 2003 08:06:47 -0000	1.11
 @@ -1474,6 +1474,7 @@ done:	/* Leave input mode. */
  
  err:
  alloc_err:
 +	F_CLR(sp, SC_TINPUT);
  	txt_err(sp, &sp->tiq);
  	return (1);
  }
 
 --ew6BAiZeqk4r7MaW
 Content-Type: text/x-diff; charset=us-ascii
 Content-Disposition: attachment; filename="nvi-netbsd-v_txt.c-4.diff"
 
 Obtained from:	NetBSD
 
 date: 2004/11/23 14:35:45;  author: aymeric;  state: Exp;  lines: +3 -3
 branches:  1.12.2;
 Move a line of code which was "obviously" misplaced.
 This fixes a core dump when auto-completing filenames and at least one of the
 file names is larger than the screen width.
 
 Bug report and fix by Peter Bex in PR#28382
 
 diff -p -u -r1.11 -r1.12
 --- v_txt.c	6 Jun 2003 08:06:47 -0000	1.11
 +++ v_txt.c	23 Nov 2004 14:35:45 -0000	1.12
 @@ -2235,8 +2235,8 @@ txt_fc_col(sp, argc, argv)
  
  	/* If the largest file name is too large, just print them. */
  	if (colwidth > sp->cols) {
 -		p = msg_print(sp, av[0]->bp + prefix, &nf);
  		for (ac = argc, av = argv; ac > 0; --ac, ++av) {
 +			p = msg_print(sp, av[0]->bp + prefix, &nf);
  			(void)ex_printf(sp, "%s\n", p);
  			if (F_ISSET(gp, G_INTERRUPTED))
  				break;
 
 --ew6BAiZeqk4r7MaW--
Responsible-Changed-From-To: freebsd-bugs->jh 
Responsible-Changed-By: jh 
Responsible-Changed-When: Tue May 4 15:41:11 UTC 2010 
Responsible-Changed-Why:  
Take. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=21089 

From: dfilter@FreeBSD.ORG (dfilter service)
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: bin/21089: commit references a PR
Date: Fri, 28 May 2010 09:30:34 +0000 (UTC)

 Author: jh
 Date: Fri May 28 09:30:13 2010
 New Revision: 208612
 URL: http://svn.freebsd.org/changeset/base/208612
 
 Log:
   Fixes from NetBSD for nvi visual mode:
   
   - Fix handling of ^@ when reading an ex command. Don't try to replay
     the previous input.
   - Fix handling of ^C in insert mode and when reading an ex command.
     Repeating an interrupted input could cause a crash and interrupting
     ex command input could cause a file corruption.
   - Fix a bug which causes crashes in file name completion when a file
     name is longer than the screen width.
   - When an error occurs in v_txt(), leave the input mode.
   
   PR:		bin/21089, bin/136393
   Obtained from:	NetBSD
 
 Modified:
   head/contrib/nvi/vi/v_ex.c
   head/contrib/nvi/vi/v_txt.c
 
 Modified: head/contrib/nvi/vi/v_ex.c
 ==============================================================================
 --- head/contrib/nvi/vi/v_ex.c	Fri May 28 09:26:53 2010	(r208611)
 +++ head/contrib/nvi/vi/v_ex.c	Fri May 28 09:30:13 2010	(r208612)
 @@ -428,6 +428,10 @@ v_ex(sp, vp)
  			if (tp->term == TERM_BS)
  				break;
  
 +			/* If the user changed their mind, return. */
 +			if (tp->term != TERM_OK)
 +				break;
 +
  			/* Log the command. */
  			if (O_STR(sp, O_CEDIT) != NULL && v_ecl_log(sp, tp))
  				return (1);
 
 Modified: head/contrib/nvi/vi/v_txt.c
 ==============================================================================
 --- head/contrib/nvi/vi/v_txt.c	Fri May 28 09:26:53 2010	(r208611)
 +++ head/contrib/nvi/vi/v_txt.c	Fri May 28 09:30:13 2010	(r208612)
 @@ -510,15 +510,6 @@ next:	if (v_event_get(sp, evp, 0, ec_fla
  	case E_EOF:
  		F_SET(sp, SC_EXIT_FORCE);
  		return (1);
 -	case E_INTERRUPT:
 -		/*
 -		 * !!!
 -		 * Historically, <interrupt> exited the user from text input
 -		 * mode or cancelled a colon command, and returned to command
 -		 * mode.  It also beeped the terminal, but that seems a bit
 -		 * excessive.
 -		 */
 -		goto k_escape;
  	case E_REPAINT:
  		if (vs_repaint(sp, &ev))
  			return (1);
 @@ -526,10 +517,37 @@ next:	if (v_event_get(sp, evp, 0, ec_fla
  	case E_WRESIZE:
  		/* <resize> interrupts the input mode. */
  		v_emsg(sp, NULL, VIM_WRESIZE);
 -		goto k_escape;
 +		/* FALLTHROUGH */
  	default:
 -		v_event_err(sp, evp);
 -		goto k_escape;
 +		if (evp->e_event != E_INTERRUPT && evp->e_event != E_WRESIZE)
 +			v_event_err(sp, evp);
 +		/*
 +		 * !!!
 +		 * Historically, <interrupt> exited the user from text input
 +		 * mode or cancelled a colon command, and returned to command
 +		 * mode.  It also beeped the terminal, but that seems a bit
 +		 * excessive.
 +		 */
 +		/*
 +		 * If we are recording, morph into <escape> key so that
 +		 * we can repeat the command safely: there is no way to
 +		 * invalidate the repetition of an instance of a command,
 +		 * which would be the alternative possibility.
 +		 * If we are not recording (most likely on the command line),
 +		 * simply discard the input and return to command mode
 +		 * so that an INTERRUPT doesn't become for example a file
 +		 * completion request. -aymeric
 +		 */
 +		if (LF_ISSET(TXT_RECORD)) {
 +			evp->e_event = E_CHARACTER;
 +			evp->e_c = 033;
 +			evp->e_flags = 0;
 +			evp->e_value = K_ESCAPE;
 +			break;
 +		} else {
 +			tp->term = TERM_ESC;
 +			goto k_escape;
 +		}
  	}
  
  	/*
 @@ -539,7 +557,7 @@ next:	if (v_event_get(sp, evp, 0, ec_fla
  	 * This was not documented as far as I know, and is a great test of vi
  	 * clones.
  	 */
 -	if (rcol == 0 && !LF_ISSET(TXT_REPLAY) && evp->e_c == '\0') {
 +	if (LF_ISSET(TXT_RECORD) && rcol == 0 && evp->e_c == '\0') {
  		if (vip->rep == NULL)
  			goto done;
  
 @@ -1456,6 +1474,7 @@ done:	/* Leave input mode. */
  
  err:
  alloc_err:
 +	F_CLR(sp, SC_TINPUT);
  	txt_err(sp, &sp->tiq);
  	return (1);
  }
 @@ -2216,8 +2235,8 @@ txt_fc_col(sp, argc, argv)
  
  	/* If the largest file name is too large, just print them. */
  	if (colwidth > sp->cols) {
 -		p = msg_print(sp, av[0]->bp + prefix, &nf);
  		for (ac = argc, av = argv; ac > 0; --ac, ++av) {
 +			p = msg_print(sp, av[0]->bp + prefix, &nf);
  			(void)ex_printf(sp, "%s\n", p);
  			if (F_ISSET(gp, G_INTERRUPTED))
  				break;
 _______________________________________________
 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"
 
State-Changed-From-To: analyzed->patched 
State-Changed-By: jh 
State-Changed-When: Fri May 28 09:53:50 UTC 2010 
State-Changed-Why:  
Patched in head (r208611). 

http://www.freebsd.org/cgi/query-pr.cgi?pr=21089 

From: dfilter@FreeBSD.ORG (dfilter service)
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: bin/21089: commit references a PR
Date: Sun,  8 Aug 2010 07:34:56 +0000 (UTC)

 Author: jh
 Date: Sun Aug  8 07:34:37 2010
 New Revision: 211060
 URL: http://svn.freebsd.org/changeset/base/211060
 
 Log:
   MFC r208612: Fixes from NetBSD for nvi visual mode
   
   PR:		bin/21089, bin/136393
 
 Modified:
   stable/8/contrib/nvi/vi/v_ex.c
   stable/8/contrib/nvi/vi/v_txt.c
 Directory Properties:
   stable/8/contrib/nvi/   (props changed)
 
 Modified: stable/8/contrib/nvi/vi/v_ex.c
 ==============================================================================
 --- stable/8/contrib/nvi/vi/v_ex.c	Sun Aug  8 07:04:27 2010	(r211059)
 +++ stable/8/contrib/nvi/vi/v_ex.c	Sun Aug  8 07:34:37 2010	(r211060)
 @@ -428,6 +428,10 @@ v_ex(sp, vp)
  			if (tp->term == TERM_BS)
  				break;
  
 +			/* If the user changed their mind, return. */
 +			if (tp->term != TERM_OK)
 +				break;
 +
  			/* Log the command. */
  			if (O_STR(sp, O_CEDIT) != NULL && v_ecl_log(sp, tp))
  				return (1);
 
 Modified: stable/8/contrib/nvi/vi/v_txt.c
 ==============================================================================
 --- stable/8/contrib/nvi/vi/v_txt.c	Sun Aug  8 07:04:27 2010	(r211059)
 +++ stable/8/contrib/nvi/vi/v_txt.c	Sun Aug  8 07:34:37 2010	(r211060)
 @@ -510,15 +510,6 @@ next:	if (v_event_get(sp, evp, 0, ec_fla
  	case E_EOF:
  		F_SET(sp, SC_EXIT_FORCE);
  		return (1);
 -	case E_INTERRUPT:
 -		/*
 -		 * !!!
 -		 * Historically, <interrupt> exited the user from text input
 -		 * mode or cancelled a colon command, and returned to command
 -		 * mode.  It also beeped the terminal, but that seems a bit
 -		 * excessive.
 -		 */
 -		goto k_escape;
  	case E_REPAINT:
  		if (vs_repaint(sp, &ev))
  			return (1);
 @@ -526,10 +517,37 @@ next:	if (v_event_get(sp, evp, 0, ec_fla
  	case E_WRESIZE:
  		/* <resize> interrupts the input mode. */
  		v_emsg(sp, NULL, VIM_WRESIZE);
 -		goto k_escape;
 +		/* FALLTHROUGH */
  	default:
 -		v_event_err(sp, evp);
 -		goto k_escape;
 +		if (evp->e_event != E_INTERRUPT && evp->e_event != E_WRESIZE)
 +			v_event_err(sp, evp);
 +		/*
 +		 * !!!
 +		 * Historically, <interrupt> exited the user from text input
 +		 * mode or cancelled a colon command, and returned to command
 +		 * mode.  It also beeped the terminal, but that seems a bit
 +		 * excessive.
 +		 */
 +		/*
 +		 * If we are recording, morph into <escape> key so that
 +		 * we can repeat the command safely: there is no way to
 +		 * invalidate the repetition of an instance of a command,
 +		 * which would be the alternative possibility.
 +		 * If we are not recording (most likely on the command line),
 +		 * simply discard the input and return to command mode
 +		 * so that an INTERRUPT doesn't become for example a file
 +		 * completion request. -aymeric
 +		 */
 +		if (LF_ISSET(TXT_RECORD)) {
 +			evp->e_event = E_CHARACTER;
 +			evp->e_c = 033;
 +			evp->e_flags = 0;
 +			evp->e_value = K_ESCAPE;
 +			break;
 +		} else {
 +			tp->term = TERM_ESC;
 +			goto k_escape;
 +		}
  	}
  
  	/*
 @@ -539,7 +557,7 @@ next:	if (v_event_get(sp, evp, 0, ec_fla
  	 * This was not documented as far as I know, and is a great test of vi
  	 * clones.
  	 */
 -	if (rcol == 0 && !LF_ISSET(TXT_REPLAY) && evp->e_c == '\0') {
 +	if (LF_ISSET(TXT_RECORD) && rcol == 0 && evp->e_c == '\0') {
  		if (vip->rep == NULL)
  			goto done;
  
 @@ -1456,6 +1474,7 @@ done:	/* Leave input mode. */
  
  err:
  alloc_err:
 +	F_CLR(sp, SC_TINPUT);
  	txt_err(sp, &sp->tiq);
  	return (1);
  }
 @@ -2216,8 +2235,8 @@ txt_fc_col(sp, argc, argv)
  
  	/* If the largest file name is too large, just print them. */
  	if (colwidth > sp->cols) {
 -		p = msg_print(sp, av[0]->bp + prefix, &nf);
  		for (ac = argc, av = argv; ac > 0; --ac, ++av) {
 +			p = msg_print(sp, av[0]->bp + prefix, &nf);
  			(void)ex_printf(sp, "%s\n", p);
  			if (F_ISSET(gp, G_INTERRUPTED))
  				break;
 _______________________________________________
 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"
 

From: dfilter@FreeBSD.ORG (dfilter service)
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: bin/21089: commit references a PR
Date: Wed,  8 Sep 2010 18:06:31 +0000 (UTC)

 Author: jh
 Date: Wed Sep  8 18:06:05 2010
 New Revision: 212328
 URL: http://svn.freebsd.org/changeset/base/212328
 
 Log:
   MFC r208612: Fixes from NetBSD for nvi visual mode
   
   PR:		bin/21089, bin/136393
 
 Modified:
   stable/7/contrib/nvi/vi/v_ex.c
   stable/7/contrib/nvi/vi/v_txt.c
 Directory Properties:
   stable/7/contrib/nvi/   (props changed)
 
 Modified: stable/7/contrib/nvi/vi/v_ex.c
 ==============================================================================
 --- stable/7/contrib/nvi/vi/v_ex.c	Wed Sep  8 18:03:40 2010	(r212327)
 +++ stable/7/contrib/nvi/vi/v_ex.c	Wed Sep  8 18:06:05 2010	(r212328)
 @@ -428,6 +428,10 @@ v_ex(sp, vp)
  			if (tp->term == TERM_BS)
  				break;
  
 +			/* If the user changed their mind, return. */
 +			if (tp->term != TERM_OK)
 +				break;
 +
  			/* Log the command. */
  			if (O_STR(sp, O_CEDIT) != NULL && v_ecl_log(sp, tp))
  				return (1);
 
 Modified: stable/7/contrib/nvi/vi/v_txt.c
 ==============================================================================
 --- stable/7/contrib/nvi/vi/v_txt.c	Wed Sep  8 18:03:40 2010	(r212327)
 +++ stable/7/contrib/nvi/vi/v_txt.c	Wed Sep  8 18:06:05 2010	(r212328)
 @@ -510,15 +510,6 @@ next:	if (v_event_get(sp, evp, 0, ec_fla
  	case E_EOF:
  		F_SET(sp, SC_EXIT_FORCE);
  		return (1);
 -	case E_INTERRUPT:
 -		/*
 -		 * !!!
 -		 * Historically, <interrupt> exited the user from text input
 -		 * mode or cancelled a colon command, and returned to command
 -		 * mode.  It also beeped the terminal, but that seems a bit
 -		 * excessive.
 -		 */
 -		goto k_escape;
  	case E_REPAINT:
  		if (vs_repaint(sp, &ev))
  			return (1);
 @@ -526,10 +517,37 @@ next:	if (v_event_get(sp, evp, 0, ec_fla
  	case E_WRESIZE:
  		/* <resize> interrupts the input mode. */
  		v_emsg(sp, NULL, VIM_WRESIZE);
 -		goto k_escape;
 +		/* FALLTHROUGH */
  	default:
 -		v_event_err(sp, evp);
 -		goto k_escape;
 +		if (evp->e_event != E_INTERRUPT && evp->e_event != E_WRESIZE)
 +			v_event_err(sp, evp);
 +		/*
 +		 * !!!
 +		 * Historically, <interrupt> exited the user from text input
 +		 * mode or cancelled a colon command, and returned to command
 +		 * mode.  It also beeped the terminal, but that seems a bit
 +		 * excessive.
 +		 */
 +		/*
 +		 * If we are recording, morph into <escape> key so that
 +		 * we can repeat the command safely: there is no way to
 +		 * invalidate the repetition of an instance of a command,
 +		 * which would be the alternative possibility.
 +		 * If we are not recording (most likely on the command line),
 +		 * simply discard the input and return to command mode
 +		 * so that an INTERRUPT doesn't become for example a file
 +		 * completion request. -aymeric
 +		 */
 +		if (LF_ISSET(TXT_RECORD)) {
 +			evp->e_event = E_CHARACTER;
 +			evp->e_c = 033;
 +			evp->e_flags = 0;
 +			evp->e_value = K_ESCAPE;
 +			break;
 +		} else {
 +			tp->term = TERM_ESC;
 +			goto k_escape;
 +		}
  	}
  
  	/*
 @@ -539,7 +557,7 @@ next:	if (v_event_get(sp, evp, 0, ec_fla
  	 * This was not documented as far as I know, and is a great test of vi
  	 * clones.
  	 */
 -	if (rcol == 0 && !LF_ISSET(TXT_REPLAY) && evp->e_c == '\0') {
 +	if (LF_ISSET(TXT_RECORD) && rcol == 0 && evp->e_c == '\0') {
  		if (vip->rep == NULL)
  			goto done;
  
 @@ -1456,6 +1474,7 @@ done:	/* Leave input mode. */
  
  err:
  alloc_err:
 +	F_CLR(sp, SC_TINPUT);
  	txt_err(sp, &sp->tiq);
  	return (1);
  }
 @@ -2216,8 +2235,8 @@ txt_fc_col(sp, argc, argv)
  
  	/* If the largest file name is too large, just print them. */
  	if (colwidth > sp->cols) {
 -		p = msg_print(sp, av[0]->bp + prefix, &nf);
  		for (ac = argc, av = argv; ac > 0; --ac, ++av) {
 +			p = msg_print(sp, av[0]->bp + prefix, &nf);
  			(void)ex_printf(sp, "%s\n", p);
  			if (F_ISSET(gp, G_INTERRUPTED))
  				break;
 _______________________________________________
 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"
 
State-Changed-From-To: patched->closed 
State-Changed-By: jh 
State-Changed-When: Fri Sep 10 04:56:07 UTC 2010 
State-Changed-Why:  
Fixed in head, stable/8 and stable/7. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=21089 
>Unformatted:
