From dan@obluda.cz  Tue Sep  3 14:37:19 2002
Return-Path: <dan@obluda.cz>
Received: from mx1.FreeBSD.org (mx1.FreeBSD.org [216.136.204.125])
	by hub.freebsd.org (Postfix) with ESMTP id 327B837B401
	for <FreeBSD-gnats-submit@freebsd.org>; Tue,  3 Sep 2002 14:37:19 -0700 (PDT)
Received: from xkulesh.vol.cz (xkulesh.vol.cz [195.250.154.106])
	by mx1.FreeBSD.org (Postfix) with ESMTP id 2D9B143E7B
	for <FreeBSD-gnats-submit@freebsd.org>; Tue,  3 Sep 2002 14:37:14 -0700 (PDT)
	(envelope-from dan@obluda.cz)
Received: from xkulesh.vol.cz (localhost [127.0.0.1])
	by xkulesh.vol.cz (8.12.5/8.12.5) with ESMTP id g83Lb8Jj000269;
	Tue, 3 Sep 2002 23:37:09 +0200 (CEST)
	(envelope-from dan@obluda.cz)
Received: (from dan@localhost)
	by xkulesh.vol.cz (8.12.6/8.12.6/Submit) id g83KMIYd009453;
	Tue, 3 Sep 2002 22:22:18 +0200 (CEST)
Message-Id: <200209032022.g83KMIYd009453@xkulesh.vol.cz>
Date: Tue, 3 Sep 2002 22:22:18 +0200 (CEST)
From: Dan Lukes <dan@obluda.cz>
Reply-To: Dan Lukes <dan@obluda.cz>
To: FreeBSD-gnats-submit@freebsd.org
Cc: dan@obluda.cz
Subject: MDXFileChunk may return 0 instead of hash
X-Send-Pr-Version: 3.113
X-GNATS-Notify:

>Number:         42384
>Category:       bin
>Synopsis:       MDXFileChunk may return 0 instead of hash
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    bmah
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Tue Sep 03 14:40:03 PDT 2002
>Closed-Date:    Sat Sep 07 09:11:57 PDT 2002
>Last-Modified:  Sat Sep  7 15:30:02 PDT 2002
>Originator:     Dan Lukes
>Release:        FreeBSD 5.0-CURRENT i386
>Organization:
Obludarium
>Environment:
src/lib/libmd/mdXhl.c,v 1.16 2002/03/25 13:50:40


>Description:
During cleaning of code of libmd from warnings:
lib/libmd/md2hl.c:
  57: warning: 'i' might be used uninitialized in this function

It is true, when MDXFileChunk called with ofs at or beyond of EOF
or with zero-length file, then n == len == 0; while loop is not
entered so 'i' remain uninitialised; despite of it is referenced 
before return. MDXFileChunk may return 0 instead of hash

The patch is based on fact that 'n' must be zero on return 
(it's better than initialising i as it waste a few CPU cycles).

>How-To-Repeat:
	N/A
>Fix:

--- lib/libmd/mdXhl.c.ORIG	Mon Jul  1 22:53:29 2002
+++ lib/libmd/mdXhl.c	Tue Sep  3 21:59:33 2002
@@ -78,7 +78,7 @@
     e = errno;
     close(f);
     errno = e;
-    if (i < 0) return 0;
+    if (n > 0) return 0;
     return MDXEnd(&ctx, buf);
 }
 
>Release-Note:
>Audit-Trail:
State-Changed-From-To: open->closed 
State-Changed-By: bmah 
State-Changed-When: Sat Sep 7 09:07:05 PDT 2002 
State-Changed-Why:  
I seem to have independently discovered the same bug (see the 
"libmd bug on -CURRENT" thread on current@).  The fix I committed 
in rev. 1.17 of mdXhl.c is more straightforward; it just initializes 
i before first use. 

Thanks for your submission! 



Responsible-Changed-From-To: freebsd-bugs->bmah 
Responsible-Changed-By: bmah 
Responsible-Changed-When: Sat Sep 7 09:07:05 PDT 2002 
Responsible-Changed-Why:  
I committed a slightly different fix. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=42384 

From: Dan Lukes <dan@obluda.cz>
To: "Bruce A. Mah" <bmah@FreeBSD.org>
Cc: freebsd-bugs@FreeBSD.org, freebsd-gnats-submit@FreeBSD.org
Subject: Re: bin/42384: MDXFileChunk may return 0 instead of hash
Date: Sat, 07 Sep 2002 21:31:12 +0200

 Bruce A. Mah wrote:
 > Synopsis: MDXFileChunk may return 0 instead of hash
 > 
 > The fix I committed
 > in rev. 1.17 of mdXhl.c is more straightforward; it just initializes
 > i before first use.
 
 	Yes, your patch works, but ...
 
 	With full respect to fact you are commiter, so final decision is your 
 suverenity  - can you think about revoking your's straightforward fix a 
 commiting my (more performance friendly) one ?
 
 	I still think that unecesarry initializing of [i] is waste of resources ...
 
 				Thanks.
 
 						Dan
 

From: bmah@FreeBSD.org (Bruce A. Mah)
To: Dan Lukes <dan@obluda.cz>
Cc: "Bruce A. Mah" <bmah@FreeBSD.org>, freebsd-bugs@FreeBSD.org,
	freebsd-gnats-submit@FreeBSD.org
Subject: Re: bin/42384: MDXFileChunk may return 0 instead of hash 
Date: Sat, 07 Sep 2002 12:48:17 -0700

 --==_Exmh_-1212473703P
 Content-Type: text/plain; charset=us-ascii
 
 If memory serves me right, Dan Lukes wrote:
 
 > 	Yes, your patch works, but ...
 > 
 > 	With full respect to fact you are commiter, so final decision is your 
 > suverenity  - can you think about revoking your's straightforward fix a 
 > commiting my (more performance friendly) one ?
 
 Hi Dan--
 
 Initializing this variable once per invocation of this function is going
 to be insignificant compared to the time that it takes to run an MD5
 computation.
 
 Cheers,
 
 Bruce.
 
 
 
 --==_Exmh_-1212473703P
 Content-Type: application/pgp-signature
 
 -----BEGIN PGP SIGNATURE-----
 Version: GnuPG v1.0.7 (FreeBSD)
 Comment: Exmh version 2.5+ 20020506
 
 iD8DBQE9elgB2MoxcVugUsMRAqvBAKDTHaAkmranMyCVBloZpEzmvIPJqwCeJeyZ
 2XAf+TksutnR0Fc28UKWoRA=
 =e2dY
 -----END PGP SIGNATURE-----
 
 --==_Exmh_-1212473703P--

From: Dan Lukes <dan@obluda.cz>
To: bmah@FreeBSD.org
Cc: freebsd-bugs@FreeBSD.org, freebsd-gnats-submit@FreeBSD.org
Subject: Re: bin/42384: MDXFileChunk may return 0 instead of hash
Date: Sun, 08 Sep 2002 00:25:27 +0200

 Bruce A. Mah wrote:
 >>	With full respect to fact you are commiter, so final decision is your 
 >>suverenity  - can you think about revoking your's straightforward fix a 
 >>commiting my (more performance friendly) one ?
 
 > Initializing this variable once per invocation of this function is going
 > to be insignificant compared to the time that it takes to run an MD5
 > computation.
 
 	Yes, the diference is few CPU cycles only, but why we waste it when 
 saving it has NO negative consequences ?
 
 	Well, you decided, i respect it.
 
 Howgh.
 
 					Dan
 
 
>Unformatted:
