From owner-freebsd-bugs Tue Dec 31 15:20:07 1996 Return-Path: Received: (from root@localhost) by freefall.freebsd.org (8.8.4/8.8.4) id PAA29718 for bugs-outgoing; Tue, 31 Dec 1996 15:20:07 -0800 (PST) Received: (from gnats@localhost) by freefall.freebsd.org (8.8.4/8.8.4) id PAA29694; Tue, 31 Dec 1996 15:20:03 -0800 (PST) Resent-Date: Tue, 31 Dec 1996 15:20:03 -0800 (PST) Resent-Message-Id: <199612312320.PAA29694@freefall.freebsd.org> Resent-From: gnats (GNATS Management) Resent-To: freebsd-bugs Resent-Reply-To: FreeBSD-gnats@freefall.FreeBSD.org, gbuchanan@sympatico.ca 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 ; 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 X-Send-Pr-Version: 3.2 Subject: bin/2339: ex/vi/nex/nvi incorrect handling of -- arg Sender: owner-bugs@freebsd.org X-Loop: FreeBSD.org Precedence: bulk >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 "+" into "-c". * 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 "+" into "-c". * 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 Ottawa, ON >Audit-Trail: >Unformatted: