Subject: bin/3112: compress -c deletes original file, etc.
To: None <gnats-bugs@gnats.netbsd.org>
From: None <bruce@zuhause.mn.org>
List: netbsd-bugs
Date: 01/15/1997 12:26:22
>Number:         3112
>Category:       bin
>Synopsis:       /usr/bin/compress -c deletes original file, tries to reset /dev/stdout info
>Confidential:   no
>Severity:       serious
>Priority:       high
>Responsible:    bin-bug-people (Utility Bug People)
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Wed Jan 15 11:05:03 1997
>Last-Modified:
>Originator:     Bruce Albrecht
>Organization:
	
>Release:        NetBSD-1.2/NetBSD-current (files have not changed since October)
>Environment:
System: NetBSD zuhause 1.2B NetBSD 1.2B (ZuHause) #0: Wed Nov 27 01:41:50 CST 1996 root@zuhause:/NetBSD-current/usr/src/sys/arch/amiga/compile/ZuHause amiga


>Description:
compress -c is supposed to compress to standard output, leaving the original file intact.
Instead, it writes to standard output, unlinks the original file, issues three warnings
about not being able to modify /dev/stdout, and returns an error code of 1.

I haven't bothered to check it, but I suspect uncompress has the same problem.
>How-To-Repeat:
	
compress -c /netbsd > x.Z

>Fix:
	
diff -c compress.c compress.c.old
*** compress.c  Wed Jan 15 12:31:52 1997
--- compress.c.old      Wed Jan 15 12:30:08 1997
***************
*** 263,269 ****
        }
        ofp = NULL;
  
!       if (isreg && ! isstdout) {
                if (stat(out, &sb)) {
                        cwarn("%s", out);
                        goto err;
--- 263,269 ----
        }
        ofp = NULL;
  
!       if (isreg) {
                if (stat(out, &sb)) {
                        cwarn("%s", out);
                        goto err;
***************
*** 361,367 ****
                goto err;
        }
  
!       if (isreg && ! isstdout) {
                setfile(out, &sb);
  
                if (unlink(in))
--- 361,367 ----
                goto err;
        }
  
!       if (isreg) {
                setfile(out, &sb);
  
                if (unlink(in))

>Audit-Trail:
>Unformatted: