Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 31 Dec 1996 18:10:02 -0500
From:      gbuchanan@sympatico.ca
To:        FreeBSD-gnats-submit@freebsd.org
Subject:   bin/2339: ex/vi/nex/nvi incorrect handling of -- arg
Message-ID:  <199612312310.SAA01006@localhost>
Resent-Message-ID: <199612312320.PAA29694@freefall.freebsd.org>

next in thread | raw e-mail | index | archive | help

>Number:         2339
>Category:       bin
>Synopsis:       ex/vi/nex/nvi incorrect handling of -- arg
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-bugs
>State:          open
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Tue Dec 31 15:20:02 PST 1996
>Last-Modified:
>Originator:     Gardner Buchanan
>Organization:
>Release:        FreeBSD 2.1-STABLE i386
>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
>Audit-Trail:
>Unformatted:



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199612312310.SAA01006>