From garys@opusnet.com  Sun Sep  4 16:46:25 2005
Return-Path: <garys@opusnet.com>
Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125])
	by hub.freebsd.org (Postfix) with ESMTP id 1539716A41F
	for <FreeBSD-gnats-submit@freebsd.org>; Sun,  4 Sep 2005 16:46:25 +0000 (GMT)
	(envelope-from garys@opusnet.com)
Received: from opusnet.com (mail.opusnet.com [209.210.200.6])
	by mx1.FreeBSD.org (Postfix) with ESMTP id C4D0543D45
	for <FreeBSD-gnats-submit@freebsd.org>; Sun,  4 Sep 2005 16:46:24 +0000 (GMT)
	(envelope-from garys@opusnet.com)
Received: from localhost.localhost [70.98.246.232] by opusnet.com with ESMTP
  (SMTPD32-8.05) id A4DA13890100; Sun, 04 Sep 2005 09:46:18 -0700
Received: from localhost.localhost (localhost.localhost [127.0.0.1])
	by localhost.localhost (8.13.3/8.13.3) with ESMTP id j84GlvAh009255
	for <FreeBSD-gnats-submit@freebsd.org>; Sun, 4 Sep 2005 09:47:57 -0700 (PDT)
	(envelope-from garys@opusnet.com)
Received: (from jojo@localhost)
	by localhost.localhost (8.13.3/8.13.3/Submit) id j84GlqbZ009254;
	Sun, 4 Sep 2005 09:47:52 -0700 (PDT)
	(envelope-from garys@opusnet.com)
Message-Id: <wkslwkhj9j.lwk@mail.opusnet.com>
Date: Sun, 04 Sep 2005 09:47:52 -0700
From: "Gary W. Swearingen" <garys@freebsd.org>
Reply-To: garys@freebsd.org
To: FreeBSD-gnats-submit@freebsd.org
Subject: uncompress(1) program emits bogus "overwrite?" prompt
X-GNATS-Notify:

>Number:         85712
>Category:       bin
>Synopsis:       uncompress(1) program emits bogus "overwrite?" prompt
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-bugs
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          change-request
>Submitter-Id:   current-users
>Arrival-Date:   Sun Sep 04 16:50:21 GMT 2005
>Closed-Date:    
>Last-Modified:  Tue Sep  6 23:30:12 GMT 2005
>Originator:     Gary W. Swearingen
>Release:        FreeBSD 5.4-RELEASE i386
>Organization:
none
>Environment:
n/a
>Description:

The uncompress(1) program, when given a filename without a .Z
extension, prompts the user for confirmation and if given "y", it then
ignores the reply and then complains about the missing .Z extension.

This PR should be suspended immediately for the "lack of resources"
reason, because it is an unimportant bug that only wastes a little
users' time.

>How-To-Repeat:
n/a

$ d yy*
1060967 -rw-r-----  1 jojo  jojo  - 11135 Sep  4 08:22:04 2005 yyy
$ uncompress yyy
overwrite yyy? y
uncompress: yyy.Z: No such file or directory
$ d yy*
1060967 -rw-r-----  1 jojo  jojo  - 11135 Sep  4 08:22:04 2005 yyy

>Fix:

Make the program abort with complaint if a filename doesn't have
a .Z extension. (Either reject only bad filenames or whole command.)
>Release-Note:
>Audit-Trail:

From: garys@opusnet.com (Gary W. Swearingen)
To: bug-followup@freebsd.org
Cc:  
Subject: Re: bin/85712: uncompress(1) program emits bogus "overwrite?"
 prompt
Date: Sun, 04 Sep 2005 10:53:59 -0700

 A similar and likely-related problem occurs with compress(1),
 which should be considered as part of this PR.
 
 $ d yy*
 1060112 -rw-r-----  1 jojo  jojo  - 23140 Sep  4 09:18:03 2005 yyy.Z
 1060544 -rw-r-----  1 jojo  jojo  - 11135 Sep  4 08:23:05 2005 yyy.bak
 1060967 -rw-r-----  1 jojo  jojo  - 23140 Sep  4 10:43:49 2005 yyy.un
 $ compress yyy
 overwrite yyy.Z? y
 compress: yyy: No such file or directory
 $ d yy*
 1060112 -rw-r-----  1 jojo  jojo  - 23140 Sep  4 09:18:03 2005 yyy.Z
 1060544 -rw-r-----  1 jojo  jojo  - 11135 Sep  4 08:23:05 2005 yyy.bak
 1060967 -rw-r-----  1 jojo  jojo  - 23140 Sep  4 10:43:49 2005 yyy.un

From: garys@opusnet.com (Gary W. Swearingen)
To: bug-followup@freebsd.org
Cc:  
Subject: Re: bin/85712: uncompress(1) program emits bogus "overwrite?"
Date: Sun, 04 Sep 2005 11:27:51 -0700

 A further unimportant bug was noticed:  When the program is used with
 a "-" arguement, it accepts standard input as the user's reply to
 the programs prompt for y/n confirmation, so, for example 
 
 $ echo yesssssssssssssssssssssssssssssssssssssss | compress yyy - >/tmp/y
 overwrite yyy.Z? compress: yyy: No such file or directory
 $ d /tmp/y
 32 -rw-r--r--  1 jojo  wheel  - 0 Sep  4 11:19:35 2005 /tmp/y
 
 instead of sending the compressed string to /tmp/y, as advertized.

From: Giorgos Keramidas <keramida@freebsd.org>
To: "Gary W. Swearingen" <garys@freebsd.org>
Cc: bug-followup@freebsd.org
Subject: Re: bin/85712: uncompress(1) program emits bogus "overwrite?" prompt
Date: Wed, 7 Sep 2005 02:20:19 +0300

 On 2005-09-04 09:47, "Gary W. Swearingen" <garys@freebsd.org> wrote:
 > The uncompress(1) program, when given a filename without a .Z
 > extension, prompts the user for confirmation and if given "y", it then
 > ignores the reply and then complains about the missing .Z extension.
 
 I can confirm this bug exists in CURRENT too.
 
 > This PR should be suspended immediately for the "lack of resources"
 > reason, because it is an unimportant bug that only wastes a little
 > users' time.
 
 Unless we get it fixed by committing the following:
 
 %%%
 Index: compress.c
 ===================================================================
 RCS file: /home/ncvs/src/usr.bin/compress/compress.c,v
 retrieving revision 1.21
 diff -u -r1.21 compress.c
 --- compress.c	14 Jun 2003 13:41:31 -0000	1.21
 +++ compress.c	6 Sep 2005 23:04:44 -0000
 @@ -204,7 +204,7 @@
  	int exists, isreg, oreg;
  	u_char buf[1024];
  
 -	exists = !stat(out, &sb);
 +	exists = (stat(in, &sb) == 0 && stat(out, &sb) == 0);
  	if (!force && exists && S_ISREG(sb.st_mode) && !permission(out))
  		return;
  	isreg = oreg = !exists || S_ISREG(sb.st_mode);
 @@ -294,7 +294,7 @@
  	int exists, isreg, oreg;
  	u_char buf[1024];
  
 -	exists = !stat(out, &sb);
 +	exists = (stat(in, &sb) == 0 && stat(out, &sb) == 0);
  	if (!force && exists && S_ISREG(sb.st_mode) && !permission(out))
  		return;
  	isreg = oreg = !exists || S_ISREG(sb.st_mode);
 %%%
 
 With this patch, the behavior of both compress and uncompress makes more
 sense, since they warn about missing input files *before* the permission()
 function checks for overwrite access.
 
 IMHO, it's ok to use stat() on both the input and output file here, since
 the checks for success and/or failure later on protect against files going
 away under compress(1) or uncompress(1) between the time the stat() and
 permission() calls run and the time the files are really opened.
 
>Unformatted:
