Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 6 Jan 2003 10:09:50 +0200
From:      Peter Pentchev <roam@ringlet.net>
To:        Giorgos Keramidas <keramida@freebsd.org>
Cc:        freebsd-audit@freebsd.org
Subject:   Re: hopefully, a fix for an old uncompress(1) bug
Message-ID:  <20030106080949.GA382@straylight.oblivion.bg>
In-Reply-To: <20030106062309.GA37109@gothmog.gr>
References:  <20030106062309.GA37109@gothmog.gr>

next in thread | previous in thread | raw e-mail | index | archive | help

[-- Attachment #1 --]
On Mon, Jan 06, 2003 at 08:23:09AM +0200, Giorgos Keramidas wrote:
> 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.

Good catch - to both Gary and you!  Just a minor note inline...

> %%%
> Index: compress.c
> ===================================================================
> 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 @@
[snip]
>  	if ((ifp = zopen(in, "r", bits)) == NULL) {
>  		cwarn("%s", in);
> -		goto err;
> +		return;

Is this change really needed?  It is true that the code at 'err' would
be a no-op at this point, when neither ifp nor ofp has been opened, but
it strikes me as a bit more semantically correct to invoke the "real"
error-handling procedures at any error, just in case something changes
in the future and some error-handling does indeed become necessary.

Other than that, the patch seems just fine - and it works :)
Attached is the version without the 'goto err' change, for the minor
convenience of future reviewers and committers.

G'luck,
Peter

-- 
Peter Pentchev	roam@ringlet.net	roam@FreeBSD.org
PGP key:	http://people.FreeBSD.org/~roam/roam.key.asc
Key fingerprint	FDBA FD79 C26F 3C51 C95E  DF9E ED18 B68D 1619 4553
If this sentence didn't exist, somebody would have invented it.

Index: src/usr.bin/compress/compress.c
===================================================================
RCS file: /home/ncvs/src/usr.bin/compress/compress.c,v
retrieving revision 1.20
diff -u -r1.20 compress.c
--- src/usr.bin/compress/compress.c	28 Jul 2002 15:32:17 -0000	1.20
+++ src/usr.bin/compress/compress.c	6 Jan 2003 08:04:51 -0000
@@ -300,11 +300,6 @@
 	isreg = oreg = !exists || S_ISREG(sb.st_mode);
 
 	ifp = ofp = NULL;
-	if ((ofp = fopen(out, "w")) == NULL) {
-		cwarn("%s", out);
-		return;
-	}
-
 	if ((ifp = zopen(in, "r", bits)) == NULL) {
 		cwarn("%s", in);
 		goto err;
@@ -316,6 +311,10 @@
 	if (!S_ISREG(sb.st_mode))
 		isreg = 0;
 
+	if ((ofp = fopen(out, "w")) == NULL) {
+		cwarn("%s", out);
+		goto err;
+	}
 	while ((nr = fread(buf, 1, sizeof(buf), ifp)) != 0)
 		if (fwrite(buf, 1, nr, ofp) != nr) {
 			cwarn("%s", out);

[-- Attachment #2 --]
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.1 (FreeBSD)

iD8DBQE+GTnN7Ri2jRYZRVMRAnD0AKCZX1XfaZWR4pPdhJKh/hAY7C6hswCffgBz
mi9ZmYanRLWwBAe/T1CMfqI=
=C3ql
-----END PGP SIGNATURE-----

Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20030106080949.GA382>