Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 19 Sep 1996 11:56:11 -0700 (PDT)
From:      Jason Thorpe <thorpej@nas.nasa.gov>
To:        FreeBSD-gnats-submit@freebsd.org
Subject:   bin/1648: libmd not 64-bit safe
Message-ID:  <199609191856.LAA11322@nostromo.nas.nasa.gov>
Resent-Message-ID: <199609191910.MAA23739@freefall.freebsd.org>

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

>Number:         1648
>Category:       bin
>Synopsis:       libmd not 64-bit safe
>Confidential:   no
>Severity:       serious
>Priority:       low
>Responsible:    freebsd-bugs
>State:          open
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Thu Sep 19 12:10:01 PDT 1996
>Last-Modified:
>Originator:     Jason Thorpe
>Organization:
Numerical Aerodynamic Simulation Project - NASA Ames
>Release:        FreeBSD-current 960918, built on NetBSD/alpha
>Environment:
	
System: NetBSD nostromo 1.2A NetBSD 1.2A (NOSY) #14: Wed Sep 18 14:54:10 PDT 1996 thorpej@nostromo:/work/clean-current/src/sys/arch/alpha/compile/NOSY alpha


>Description:
	The "md" library is not 64-bit safe.  It makes assumptions
	about the size of shorts and longs.

>How-To-Repeat:
	Build the md library under NetBSD/alpha.  It will build fine,
	but the regression test will fail.

>Fix:
	Diffs below for md4/md5.  Note I did not make the necessary
	modifications to md2; I am not interested in using md2
	due to the md2 license.  However, the changes to md2 would
	be quite similar to the changes to md4/md5.

 ----- snip -----
Index: md4.h
===================================================================
RCS file: /mastersrc/netbsd/src/lib/libmd/md4.h,v
retrieving revision 1.1.1.1
retrieving revision 1.3
diff -c -r1.1.1.1 -r1.3
*** md4.h	1996/09/19 06:32:20	1.1.1.1
--- md4.h	1996/09/19 18:45:42	1.3
***************
*** 24,33 ****
--- 24,45 ----
  
  #ifndef _MD4_H_
  #define _MD4_H_
+ 
+ #include <sys/types.h>
+ 
  /* MD4 context. */
  typedef struct MD4Context {
+ #if 0
    unsigned long state[4];	/* state (ABCD) */
    unsigned long count[2];	/* number of bits, modulo 2^64 (lsb first) */
+ #else
+   /*
+    * Within the MD4 library, these are treated as 4-byte quantities,
+    * and thus _must_ be declared this way.
+    */
+   u_int32_t state[4];		/* state (ABCD) */
+   u_int32_t count[2];		/* number of bits, modulo 2^64 (lsb first) */
+ #endif /* 0 */
    unsigned char buffer[64];	/* input buffer */
  } MD4_CTX;
  
Index: md4c.c
===================================================================
RCS file: /mastersrc/netbsd/src/lib/libmd/md4c.c,v
retrieving revision 1.1.1.1
retrieving revision 1.3
diff -c -r1.1.1.1 -r1.3
*** md4c.c	1996/09/19 06:32:20	1.1.1.1
--- md4c.c	1996/09/19 18:45:44	1.3
***************
*** 22,33 ****
     documentation and/or software.
   */
  
! #include "md4.h"
  #include <string.h>
  
  typedef unsigned char *POINTER;
  typedef unsigned short int UINT2;
  typedef unsigned long int UINT4;
  
  #define PROTO_LIST(list) list
  
--- 22,40 ----
     documentation and/or software.
   */
  
! #include <sys/types.h>
  #include <string.h>
  
+ #include "md4.h"
+ 
  typedef unsigned char *POINTER;
+ #if 0
  typedef unsigned short int UINT2;
  typedef unsigned long int UINT4;
+ #else
+ typedef u_int16_t UINT2;
+ typedef u_int32_t UINT4;	/* MUST be this for 64-bit systems */
+ #endif /* 0 */
  
  #define PROTO_LIST(list) list
  
Index: md5.h
===================================================================
RCS file: /mastersrc/netbsd/src/lib/libmd/md5.h,v
retrieving revision 1.1.1.1
retrieving revision 1.3
diff -c -r1.1.1.1 -r1.3
*** md5.h	1996/09/19 06:32:20	1.1.1.1
--- md5.h	1996/09/19 18:45:46	1.3
***************
*** 25,34 ****
--- 25,46 ----
  
  #ifndef _MD5_H_
  #define _MD5_H_
+ 
+ #include <sys/types.h>
+ 
  /* MD5 context. */
  typedef struct MD5Context {
+ #if 0
    unsigned long state[4];	/* state (ABCD) */
    unsigned long count[2];	/* number of bits, modulo 2^64 (lsb first) */
+ #else
+   /*
+    * Within the MD5 library, these are treated as 4-byte quantities,
+    * and thus _must_ be declared this way.
+    */
+   u_int32_t state[4];		/* state (ABCD) */
+   u_int32_t count[2];		/* number of bits, modulo 2^64 (lsb first) */
+ #endif /* 0 */
    unsigned char buffer[64];	/* input buffer */
  } MD5_CTX;
  
Index: md5c.c
===================================================================
RCS file: /mastersrc/netbsd/src/lib/libmd/md5c.c,v
retrieving revision 1.1.1.1
retrieving revision 1.3
diff -c -r1.1.1.1 -r1.3
*** md5c.c	1996/09/19 06:32:19	1.1.1.1
--- md5c.c	1996/09/19 18:45:47	1.3
***************
*** 23,34 ****
  documentation and/or software.
   */
  
! #include "md5.h"
  #include <string.h>
  
  typedef unsigned char *POINTER;
  typedef unsigned short int UINT2;
  typedef unsigned long int UINT4;
  
  #define PROTO_LIST(list) list
  
--- 23,41 ----
  documentation and/or software.
   */
  
! #include <sys/types.h>
  #include <string.h>
  
+ #include "md5.h"
+ 
  typedef unsigned char *POINTER;
+ #if 0
  typedef unsigned short int UINT2;
  typedef unsigned long int UINT4;
+ #else
+ typedef u_int16_t UINT2;
+ typedef u_int32_t UINT4;	/* MUST be this for 64-bit systems */
+ #endif /* 0 */
  
  #define PROTO_LIST(list) list
  
>Audit-Trail:
>Unformatted:



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