Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 30 Jun 2009 21:20:58 GMT
From:      Chris Cowart <ccowart@rescomp.berkeley.edu>
To:        freebsd-gnats-submit@FreeBSD.org
Subject:   ports/136197: [patch] net-p2p/bnbt sha1 implementation broken for amd64 builds
Message-ID:  <200906302120.n5ULKwIH097280@www.freebsd.org>
Resent-Message-ID: <200906302130.n5ULU2RZ078537@freefall.freebsd.org>

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

>Number:         136197
>Category:       ports
>Synopsis:       [patch] net-p2p/bnbt sha1 implementation broken for amd64 builds
>Confidential:   no
>Severity:       serious
>Priority:       low
>Responsible:    freebsd-ports-bugs
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:
>Class:          change-request
>Submitter-Id:   current-users
>Arrival-Date:   Tue Jun 30 21:30:02 UTC 2009
>Closed-Date:
>Last-Modified:
>Originator:     Chris Cowart
>Release:        7.1-RELEASE
>Organization:
UC Berkeley - RSSP-IT
>Environment:
FreeBSD test-aux.rescomp.berkeley.edu 7.0-RELEASE-p6 FreeBSD 7.0-RELEASE-p6 #4: Tue Dec  9 22:10:55 PST 2008     root@test-aux.rescomp.berkeley.edu:/usr/obj/usr/src/sys/AUX  amd64
>Description:
I built and deployed bnbt on our dev environment:

FreeBSD dev-aux.rescomp.berkeley.edu 7.1-RELEASE-p5 FreeBSD 7.1-RELEASE-p5 #0: Tue May 19 16:31:23 PDT 2009     root@dev-aux.rescomp.berkeley.edu:/usr/obj/usr/src/sys/AUX_DEV  i386

It would. I went to reproduce in our staging environment:

FreeBSD test-aux.rescomp.berkeley.edu 7.0-RELEASE-p6 FreeBSD 7.0-RELEASE-p6 #4: Tue Dec  9 22:10:55 PST 2008     root@test-aux.rescomp.berkeley.edu:/usr/obj/usr/src/sys/AUX  amd64

and it did not work. After several hours of troubleshooting, I realized that
BNBT was reporting a different info hash on amd64 builds than x86 builds
even though the clients had the same hash regardless of architecture. After
some help from Jonathan Chu <milki@rescomp.berkeley.edu>, we tracked down
the offending file, which assumed the length of longs was 32 bits. This didn't
work when building the software on an amd64 architecture.

The attached patch changes the long declarations to int, regardless of 
architecture, which is tested and working for both x86 and amd64.
>How-To-Repeat:
Build BNBT on an amd64 box and try to load torrents.
>Fix:
Attached patch.

Patch attached with submission follows:

diff -x .svn -Nrub /usr/ports/net-p2p/bnbt/Makefile /home/ccowart/src/sysadmin/ports/bnbt/Makefile
--- /usr/ports/net-p2p/bnbt/Makefile	2008-07-02 02:14:13.000000000 -0700
+++ /home/ccowart/src/sysadmin/ports/bnbt/Makefile	2009-06-30 14:08:28.000000000 -0700
@@ -7,6 +7,7 @@
 
 PORTNAME=	bnbt
 PORTVERSION=	8.5
+PORTREVISION=	1
 CATEGORIES=	net-p2p
 MASTER_SITES=	http://opensource.depthstrike.com/${PORTNAME}/
 DISTNAME=	${SNAPSHOT}-${PORTNAME}${PORTVERSION:C/\.//}-src
diff -x .svn -Nrub /usr/ports/net-p2p/bnbt/files/patch-sha1.cpp /home/ccowart/src/sysadmin/ports/bnbt/files/patch-sha1.cpp
--- /usr/ports/net-p2p/bnbt/files/patch-sha1.cpp	1969-12-31 16:00:00.000000000 -0800
+++ /home/ccowart/src/sysadmin/ports/bnbt/files/patch-sha1.cpp	2009-06-30 14:08:28.000000000 -0700
@@ -0,0 +1,32 @@
+--- sha1.cpp	2009-06-30 14:02:51.000000000 -0700
++++ sha1.cpp.new	2009-06-30 14:02:47.000000000 -0700
+@@ -44,9 +44,9 @@
+ 	m_count[1] = 0;
+ }
+ 
+-void CSHA1::Transform(unsigned long state[5], const unsigned char buffer[64])
++void CSHA1::Transform(unsigned int state[5], const unsigned char buffer[64])
+ {
+-	unsigned long a = 0, b = 0, c = 0, d = 0, e = 0;
++	unsigned int a = 0, b = 0, c = 0, d = 0, e = 0;
+ 
+ 	SHA1_WORKSPACE_BLOCK* block;
+ 	static unsigned char workspace[64];
+@@ -96,7 +96,7 @@
+ // Use this function to hash in binary data and strings
+ void CSHA1::Update(const unsigned char* data, unsigned int len)
+ {
+-	unsigned long i = 0, j = 0;
++	unsigned int i = 0, j = 0;
+ 
+ 	j = (m_count[0] >> 3) & 63;
+ 
+@@ -123,7 +123,7 @@
+ 
+ void CSHA1::Final()
+ {
+-	unsigned long i = 0, j = 0;
++	unsigned int i = 0, j = 0;
+ 	unsigned char finalcount[8] = { 0, 0, 0, 0, 0, 0, 0, 0 };
+ 
+ 	for (i = 0; i < 8; i++)
diff -x .svn -Nrub /usr/ports/net-p2p/bnbt/files/patch-sha1.h /home/ccowart/src/sysadmin/ports/bnbt/files/patch-sha1.h
--- /usr/ports/net-p2p/bnbt/files/patch-sha1.h	1969-12-31 16:00:00.000000000 -0800
+++ /home/ccowart/src/sysadmin/ports/bnbt/files/patch-sha1.h	2009-06-30 14:08:28.000000000 -0700
@@ -0,0 +1,31 @@
+--- sha1.h	2009-06-30 14:02:51.000000000 -0700
++++ sha1.h.new	2009-06-30 14:02:47.000000000 -0700
+@@ -59,7 +59,7 @@
+ 
+ 	typedef union {
+ 		unsigned char c[64];
+-		unsigned long l[16];
++		unsigned int l[16];
+ 	} SHA1_WORKSPACE_BLOCK;
+ 
+ 	// Two different formats for ReportHash(...)
+@@ -69,8 +69,8 @@
+ 	CSHA1();
+ 	virtual ~CSHA1();
+ 
+-	unsigned long m_state[5];
+-	unsigned long m_count[2];
++	unsigned int m_state[5];
++	unsigned int m_count[2];
+ 	unsigned char m_buffer[64];
+ 	unsigned char m_digest[20];
+ 
+@@ -86,7 +86,7 @@
+ 
+ private:
+ 	// Private SHA-1 transformation
+-	void Transform(unsigned long state[5], const unsigned char buffer[64]);
++	void Transform(unsigned int state[5], const unsigned char buffer[64]);
+ };
+ 
+ #endif // ___SHA1_H___


>Release-Note:
>Audit-Trail:
>Unformatted:



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