Bug 12801

Summary: [patch] nvi(1) infinite recursion with options "leftright" and "comment"
Product: Base System Reporter: Alexander Litvin <archer>
Component: binAssignee: freebsd-bugs (Nobody) <bugs>
Status: Closed FIXED    
Severity: Affects Only Me CC: emaste
Priority: Normal    
Version: 4.0-CURRENT   
Hardware: Any   
OS: Any   
Attachments:
Description Flags
file.dat
none
vi.diff
none
vi.diff none

Description Alexander Litvin 1999-07-25 08:10:00 UTC
The simultanious usage of the vi editor options 'comment' (skip leading
comments) and 'leftright' (do left-right scrolling) may lead to the
infinite recursion: on src/contrib/nvi/vi/vs_refresh.c:626 vs_paint()
function called recursively from itself. The result is that stack is
exhausted and process receives segfault.

Fix: 

The workaround is obviously not use 'comment' and 'leftright' options
simultaniously.
How-To-Repeat: 
1. Create the ${HOME}/.exrc file with two lines:

set leftright
set comment

or, add these lines to the existing .exrc;

2. Open any file with a few shell, C or C++ comment lines in the beginning;

3. Try to open any non-existent (new) file from the same editing session
by invoking ex "edit" command.
Comment 1 Sheldon Hearn 1999-07-26 11:15:53 UTC
> The simultanious usage of the vi editor options 'comment' (skip leading
> comments) and 'leftright' (do left-right scrolling) may lead to the
> infinite recursion: on src/contrib/nvi/vi/vs_refresh.c:626 vs_paint()

In the current sources, it's line 696. We're failing a sanity check,
which causes an abort(3) if the program is compiled with -DDEBUG.

Your How-To-Repeat is solid. I'll take a look.

Ciao,
Sheldon.
Comment 2 Sheldon Hearn freebsd_committer freebsd_triage 1999-07-27 10:37:41 UTC
State Changed
From-To: open->suspended

Since nvi is in the contrib tree, I've mailed the author with a detailed 
description of the problem. Suspended just means its not feasible for 
FreeBSD developers to be looking at the problem right now. If Keith 
determines that this is a vnedor-specific problem, I'll change the  
state. 


Comment 3 Sheldon Hearn freebsd_committer freebsd_triage 1999-07-27 10:37:41 UTC
Responsible Changed
From-To: freebsd-bugs->sheldonh

This one's on my list. 
Comment 4 Mike Heffner freebsd_committer freebsd_triage 2001-07-06 01:26:35 UTC
State Changed
From-To: suspended->feedback

Is this fixed with the patch in bin/28687?
Comment 5 Mike Heffner freebsd_committer freebsd_triage 2001-07-07 12:09:44 UTC
State Changed
From-To: feedback->open

Submitter reports this problem is not fixed with patch for bin/12801.
Comment 6 archer 2001-08-15 04:43:50 UTC
> In message about "Re: bin/12801: nvi infinite recursion with options "leftright" and "comment""
>  on Fri, Jul 06, 2001, at 08:48:09 AM you wrote:
> 
> > > Synopsis: nvi infinite recursion with options "leftright" and "comment"
> > > 
> > > State-Changed-From-To: suspended->feedback
> > > State-Changed-By: mikeh
> > > State-Changed-When: Thu Jul 5 17:26:35 PDT 2001
> > > State-Changed-Why: 
> > > Is this fixed with the patch in bin/28687?
> > 
> > Should be. :-)
> 
> No, unfortunately it's not.

Actually, as I investigated the problem, it is more severe
then just using to incompatible options. That is, this
infinite recursion can be "achieved" even without "comment"
option -- it is enougth, for example, to do the following:

1) go to the line with number NUM, where
   1 < NUM < "screen height"/2;
2) make the line to be on the top of the screen
   (e.g. by z+<Enter>);
3) do :e <non-existent file>

What I figured is that during switching files vi somehow
messes up the old and new state -- like sp (pointer to
screen structure?) already contains (mostly) info about
new file, but HMAP macro (what's this exactly?) still
has information about old file position. The fact that
this mess really works through vs_refresh() is, IMHO,
accidential.

The attached patch seems to fix the problem. This is sort
of hack, because I don't exactly understand the guts of vi,
and I have no idea how produce politically correct fix.
But at least it doesn't do anything bad (IMHO).

--- 
Laugh at your problems; everybody else does.
Comment 7 mheffner 2001-08-15 04:59:12 UTC
This message is in MIME format
Comment 8 Sheldon Hearn freebsd_committer freebsd_triage 2001-11-27 18:16:19 UTC
Responsible Changed
From-To: sheldonh->freebsd-bugs

I don't have time to get stuck into this one again.  Anyway, people 
seem to have declared open season on the vendor branch for nvi and 
there are even rumours of an impending new release.  Again.  ;-)
Comment 9 zy 2013-11-02 09:15:05 UTC
Fixed by https://github.com/lichray/nvi2/commit/3c7a9a74038f593ab4a437cfe8f791092a796b1e
;
will be imported latter.

-- 
Zhihao Yuan, ID lichray
The best way to predict the future is to invent it.
___________________________________________________
4BSD -- http://4bsd.biz/
Comment 10 Ed Maste freebsd_committer freebsd_triage 2017-11-22 02:09:55 UTC
Looks like fix was imported in r257999.