From gardner@freefall.freebsd.org  Tue Dec 31 15:10:44 1996
Received: from localhost (ppp1754.on.sympatico.ca [206.172.228.26])
          by freefall.freebsd.org (8.8.4/8.8.4) with SMTP id PAA29505
          for <FreeBSD-gnats-submit@freebsd.org>; Tue, 31 Dec 1996 15:10:40 -0800 (PST)
Received: (from gardner@localhost) by localhost (8.6.12/8.6.12) id SAA01006; Tue, 31 Dec 1996 18:10:02 -0500
Message-Id: <199612312310.SAA01006@localhost>
Date: Tue, 31 Dec 1996 18:10:02 -0500
From: gbuchanan@sympatico.ca
Reply-To: gbuchanan@sympatico.ca
To: FreeBSD-gnats-submit@freebsd.org
Subject: ex/vi/nex/nvi incorrect handling of -- arg
X-Send-Pr-Version: 3.2

>Number:         2339
>Category:       bin
>Synopsis:       ex/vi/nex/nvi incorrect handling of -- arg
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-bugs
>State:          closed
>Quarter:
>Keywords:
>Date-Required:
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Tue Dec 31 15:20:02 PST 1996
>Closed-Date:    Fri Jan 3 01:22:00 PST 1997
>Last-Modified:  Fri Jan  3 01:22:46 PST 1997
>Originator:     Gardner Buchanan
>Release:        FreeBSD 2.1-STABLE i386
>Organization:
>Environment:

Seen in 2.1-RELEASE, 2.1.6-RELEASE

>Description:

nvi and friends do something weird when asked to edit a
file whose name begins with a plus (+).  This is as a
result of some broken code which nominally handles
compatibility with the original vi's handling of +options.

>How-To-Repeat:

Do this:

   vi -- +x

You will be editing a file called "-cx".  Certainly not
what you would expect.

Doing:

  vi +x

Does something unexpected too, but in the spirit of
getopt(3), the -- should protect me from that, and it
doesn't.

>Fix:

Apply this patch to /usr/src/usr.bin/vi/common/main.c

------------------------------------------------------------------------
*** main.c.old	Tue Dec 31 17:50:52 1996
--- main.c	Tue Dec 31 17:58:49 1996
***************
*** 677,687 ****
  	 * Translate old style arguments into something getopt will like.
  	 * Make sure it's not text space memory, because ex changes the
  	 * strings.
  	 *	Change "+" into "-c$".
  	 *	Change "+<anything else>" into "-c<anything else>".
  	 *	Change "-" into "-s"
  	 */
! 	while (*++argv)
  		if (argv[0][0] == '+') {
  			if (argv[0][1] == '\0') {
  				MALLOC_NOMSG(NULL, argv[0], char *, 4);
--- 677,693 ----
  	 * Translate old style arguments into something getopt will like.
  	 * Make sure it's not text space memory, because ex changes the
  	 * strings.
+ 	 *	Leave anything after "--" alone. (Like getopt(3))
  	 *	Change "+" into "-c$".
  	 *	Change "+<anything else>" into "-c<anything else>".
  	 *	Change "-" into "-s"
  	 */
! 	while (*++argv) {
! 		if (argv[0][0] == '-' &&
! 		    argv[0][1] == '-' &&
! 		    argv[0][2] == '\0')
! 			break;
! 
  		if (argv[0][0] == '+') {
  			if (argv[0][1] == '\0') {
  				MALLOC_NOMSG(NULL, argv[0], char *, 4);
***************
*** 704,709 ****
--- 710,716 ----
  				err(1, NULL);
  			(void)strcpy(argv[0], "-s");
  		}
+ 	}
  }
  
  static void
------------------------------------------------------------------------

Have fun.

============================================
Gardner Buchanan    <gbuchanan@sympatico.ca>
Ottawa, ON
>Release-Note:
>Audit-Trail:
State-Changed-From-To: open->closed 
State-Changed-By: fenner 
State-Changed-When: Fri Jan 3 01:22:00 PST 1997 
State-Changed-Why:  
This bug does not appear to be present in the version of 
nvi in 2.2 and -current . 
>Unformatted:
