From owner-freebsd-bugs Wed Oct 11 12:50: 8 2000 Delivered-To: freebsd-bugs@freebsd.org Received: from freefall.freebsd.org (freefall.FreeBSD.org [216.136.204.21]) by hub.freebsd.org (Postfix) with ESMTP id 7D99537B66E for ; Wed, 11 Oct 2000 12:50:01 -0700 (PDT) Received: (from gnats@localhost) by freefall.freebsd.org (8.9.3/8.9.2) id MAA10911; Wed, 11 Oct 2000 12:50:01 -0700 (PDT) (envelope-from gnats@FreeBSD.org) Received: from h132-197-97-45.gte.com (h132-197-97-45.gte.com [132.197.97.45]) by hub.freebsd.org (Postfix) with ESMTP id 8263737B787; Wed, 11 Oct 2000 12:17:39 -0700 (PDT) Received: (from ak03@localhost) by h132-197-97-45.gte.com (8.11.0/8.11.0) id e9BJHOb80947; Wed, 11 Oct 2000 15:17:24 -0400 (EDT) (envelope-from ak03) Message-Id: <200010111917.e9BJHOb80947@h132-197-97-45.gte.com> Date: Wed, 11 Oct 2000 15:17:24 -0400 (EDT) From: ak03@gte.com Reply-To: ak03@gte.com To: FreeBSD-gnats-submit@freebsd.org Cc: des@freebsd.org X-Send-Pr-Version: 3.2 Subject: bin/21918: Unjustified basename code removal and subsequent breakage Sender: owner-freebsd-bugs@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.org >Number: 21918 >Category: bin >Synopsis: Revision 1.5 provides incomplete fix for 1.4 breakage by DES >Confidential: no >Severity: serious >Priority: high >Responsible: freebsd-bugs >State: open >Quarter: >Keywords: >Date-Required: >Class: sw-bug >Submitter-Id: current-users >Arrival-Date: Wed Oct 11 12:50:01 PDT 2000 >Closed-Date: >Last-Modified: >Originator: Alexander Kabaev >Release: FreeBSD 5.0-CURRENT i386 >Organization: Verizon Laboratories Inc. >Environment: FreeBSD-CURRENT PRE_SMPNG and later >Description: The comment on the old (correct) revision states that: If the suffix operand is present, is not identical to the characters remaining in string, and is identical to a suffix of the characters remaining in string, the suffix suffix shall be removed from string. The new version removes suffix even when suffix is identical to the remaining string itself. That is clearly not the behaviour both comment and basename man page describe. >How-To-Repeat: in sh: % basename filename.ext filename.ext % in ksh: % basename filename.ext filename.ext filename.ext % >Fix: Index: basename.c =================================================================== RCS file: /usr/ncvs/src/usr.bin/basename/basename.c,v retrieving revision 1.5 diff -u -r1.5 basename.c --- basename.c 2000/09/06 07:28:02 1.5 +++ basename.c 2000/10/11 19:00:43 @@ -56,7 +56,7 @@ int argc; char **argv; { - char *p, *q; + char *p; int ch; while ((ch = getopt(argc, argv, "")) != -1) @@ -73,8 +73,25 @@ if ((p = basename(argv[0])) == NULL) err(1, "%s", argv[0]); - if (*++argv && (q = strstr(p, *argv)) && strcmp(q, *argv) == 0) - *q = '\0'; + + /* + * If the suffix operand is present, is not identical to the + * characters remaining in string, and is identical to a suffix + * of the characters remaining in string, the suffix + * shall be removed from string. + */ + if (*++argv) { + int suffixlen, stringlen, off; + + suffixlen = strlen(*argv); + stringlen = strlen(p); + + if (suffixlen < stringlen) { + off = stringlen - suffixlen; + if (!strcmp(p + off, *argv)) + p[off] = '\0'; + } + } (void)printf("%s\n", p); exit(0); } >Release-Note: >Audit-Trail: >Unformatted: Alexander N. Kabaev To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-bugs" in the body of the message