From owner-freebsd-audit Sun Jan 5 23:50:45 2003 Delivered-To: freebsd-audit@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id A4A9437B401 for ; Sun, 5 Jan 2003 23:50:42 -0800 (PST) Received: from mailsrv.otenet.gr (mailsrv.otenet.gr [195.170.0.5]) by mx1.FreeBSD.org (Postfix) with ESMTP id BECE743ED1 for ; Sun, 5 Jan 2003 23:50:41 -0800 (PST) (envelope-from keramida@freebsd.org) Received: from gothmog.gr (patr530-a233.otenet.gr [212.205.215.233]) by mailsrv.otenet.gr (8.12.6/8.12.6) with ESMTP id h067oY4V020063 for ; Mon, 6 Jan 2003 09:50:37 +0200 (EET) Received: from gothmog.gr (gothmog [127.0.0.1]) by gothmog.gr (8.12.6/8.12.6) with ESMTP id h067oXbl000789 for ; Mon, 6 Jan 2003 09:50:34 +0200 (EET) (envelope-from keramida@freebsd.org) Received: (from giorgos@localhost) by gothmog.gr (8.12.6/8.12.6/Submit) id h066NAtY037143 for freebsd-audit@freebsd.org; Mon, 6 Jan 2003 08:23:10 +0200 (EET) (envelope-from keramida@freebsd.org) Date: Mon, 6 Jan 2003 08:23:09 +0200 From: Giorgos Keramidas To: freebsd-audit@freebsd.org Subject: hopefully, a fix for an old uncompress(1) bug Message-ID: <20030106062309.GA37109@gothmog.gr> Mime-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="Dxnq1zWXvFF0Q93v" Content-Disposition: inline Sender: owner-freebsd-audit@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG --Dxnq1zWXvFF0Q93v Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable Gary Swearingen brought the following bug to my attention while posting a `fix' for the manpage of compress(1) and uncompress(1). Instead of documenting the bug, I thought we might try to fix it. When uncompress is called with an input filename that does not end in a .Z extension, it attempts to add the necessary extension anyway. The order of file opening in the compress() and decompress() functions is reversed though, and it causes the following `interesting' behavior: % ls -l -rw-rw-r-- 1 giorgos wheel - 0 Jan 6 08:04 lala % uncompress -f lala uncompress: lala.Z: No such file or directory % ls -l % The file called `lala' just happened to have an unfortunate file name and was unlinked at the end of decompress() function :-/ The following patch seems to fix this for me, but I'm not sure if it breaks the `expected' behavior of uncompress for some case I haven't thought about yet. The compress() and decompress() functions in compress.c are almost identical and they have been since revision 1.1 of the file, and I have only tested this lightly: % ls -l total 16 -rw-rw-r-- 1 giorgos wheel - 0 Jan 6 08:17 bar -rwxrwxr-x 1 giorgos wheel - 14681 Jan 6 08:04 uncompress % ./uncompress -f bar uncompress: bar.Z: No such file or directory % ls -l total 16 -rw-rw-r-- 1 giorgos wheel - 0 Jan 6 08:17 bar -rwxrwxr-x 1 giorgos wheel - 14681 Jan 6 08:04 uncompress % What's your opinion all? %%% Index: compress.c =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D RCS file: /home/ncvs/src/usr.bin/compress/compress.c,v retrieving revision 1.20 diff -u -5 -r1.20 compress.c --- compress.c 28 Jul 2002 15:32:17 -0000 1.20 +++ compress.c 6 Jan 2003 06:15:06 -0000 @@ -298,26 +298,25 @@ if (!force && exists && S_ISREG(sb.st_mode) && !permission(out)) return; isreg =3D oreg =3D !exists || S_ISREG(sb.st_mode); =20 ifp =3D ofp =3D NULL; - if ((ofp =3D fopen(out, "w")) =3D=3D NULL) { - cwarn("%s", out); - return; - } - if ((ifp =3D zopen(in, "r", bits)) =3D=3D NULL) { cwarn("%s", in); - goto err; + return; } if (stat(in, &sb)) { cwarn("%s", in); goto err; } if (!S_ISREG(sb.st_mode)) isreg =3D 0; =20 + if ((ofp =3D fopen(out, "w")) =3D=3D NULL) { + cwarn("%s", out); + goto err; + } while ((nr =3D fread(buf, 1, sizeof(buf), ifp)) !=3D 0) if (fwrite(buf, 1, nr, ofp) !=3D nr) { cwarn("%s", out); goto err; } %%% --Dxnq1zWXvFF0Q93v Content-Type: application/pgp-signature Content-Disposition: inline -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.2.1 (FreeBSD) iD8DBQE+GSDN1g+UGjGGA7YRAv1LAJ9b3aPht3Xpy5OjRIGWw5zY5q5mIgCdFMYy hC59Wi5t9n2VPBLRjW+Cklk= =/zIe -----END PGP SIGNATURE----- --Dxnq1zWXvFF0Q93v-- To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-audit" in the body of the message