Package: hfsprogs
Version: 332.14-4
Followup-For: Bug #436159

Hi,

after you mentioned your difficulties with 64bit on irc I looked at it
and it was quite simple to fix. There are 2 things they did wrong (in
regards to 64bit, lots of other stuff wrong there too :).

First BTPrivate.h:

-       UInt32                                           refCon;                
        //      Used by DFA to point to private data.
+       struct BTreeExtensionsRec                       *refCon;                
        //      Used by DFA to point to private data.

The refCon is always used as pointer to a struct BTreeExtensionsRec so
I added a forward declaration of the struct and made it a pointer to
one. The code works fine with "void *refCon" though as it is cast
correctly when used. Use that if you don't like the forward
declaration.

All that remained then was to remove the (UInt32) casts for all refCon usage.


Secondly:
                        nextRecord = (char *)src->buffer + srcOffs[i-1];

A construct like that is used several times with i=0 to get
srcOffs[-1]. The problem here is "UInt32 i". When i=0 the i-1 gives
4294967295 and not -1. In 32bit that results in the same because the
array pointer overflows. But in 64bit it happily accesses element
4294967295 and segfaults. By changing i to int the desired [-1] is
used.

With these two changes both mkfs and fsck run on /dev/ram0. The patch
removes the -m32 from rules and adds -W to CFLAGS. There are a lot of
warnings there that warant cleanup but nothing obviously wrong. Now
someone has to do some real life testing to see if any other 64bit
problems remain.

MfG
        Goswin

-- System Information:
Debian Release: lenny/sid
  APT prefers unstable
  APT policy: (500, 'unstable')
Architecture: amd64 (x86_64)

Kernel: Linux 2.6.22.2-mrvn
Locale: LANG=C, LC_CTYPE=de_DE (charmap=ISO-8859-1)
Shell: /bin/sh linked to /bin/bash
Index: hfsprogs-332.14/fsck_hfs.tproj/dfalib/SControl.c
===================================================================
--- hfsprogs-332.14.orig/fsck_hfs.tproj/dfalib/SControl.c	2008-05-24 14:02:06.000000000 +0200
+++ hfsprogs-332.14/fsck_hfs.tproj/dfalib/SControl.c	2008-05-24 14:02:06.000000000 +0200
@@ -981,7 +981,7 @@
 		btcbP = (BTreeControlBlock*)fcbP->fcbBtree;
 		if ( btcbP != nil)
 		{
-			if( btcbP->refCon != (UInt32)nil )
+			if( btcbP->refCon != nil )
 			{
 				if(((BTreeExtensionsRec*)btcbP->refCon)->BTCBMPtr != nil)
 				{
@@ -990,13 +990,13 @@
 				}
 				DisposeMemory( (Ptr)btcbP->refCon );
 				err = MemError();
-				btcbP->refCon = (UInt32)nil;
+				btcbP->refCon = nil;
 			}
 				
 			fcbP = GPtr->calculatedCatalogFCB;	//	release catalog BTree bit map
 			btcbP = (BTreeControlBlock*)fcbP->fcbBtree;
 				
-			if( btcbP->refCon != (UInt32)nil )
+			if( btcbP->refCon != nil )
 			{
 				if(((BTreeExtensionsRec*)btcbP->refCon)->BTCBMPtr != nil)
 				{
@@ -1005,7 +1005,7 @@
 				}
 				DisposeMemory( (Ptr)btcbP->refCon );
 				err = MemError();
-				btcbP->refCon = (UInt32)nil;
+				btcbP->refCon = nil;
 			}
 		}
 	}
Index: hfsprogs-332.14/fsck_hfs.tproj/dfalib/SVerify1.c
===================================================================
--- hfsprogs-332.14.orig/fsck_hfs.tproj/dfalib/SVerify1.c	2008-05-24 14:02:04.000000000 +0200
+++ hfsprogs-332.14/fsck_hfs.tproj/dfalib/SVerify1.c	2008-05-24 14:02:06.000000000 +0200
@@ -777,8 +777,8 @@
 	//
 	//	set up our DFA extended BTCB area.  Will we have enough memory on all HFS+ volumes.
 	//
-	btcb->refCon = (UInt32) AllocateClearMemory( sizeof(BTreeExtensionsRec) );			// allocate space for our BTCB extensions
-	if ( btcb->refCon == (UInt32) nil ) {
+	btcb->refCon = AllocateClearMemory( sizeof(BTreeExtensionsRec) );			// allocate space for our BTCB extensions
+	if ( btcb->refCon == nil ) {
 		err = R_NoMem;
 		goto exit;
 	}
@@ -1121,8 +1121,8 @@
 	//	set up our DFA extended BTCB area.  Will we have enough memory on all HFS+ volumes.
 	//
 
-	btcb->refCon = (UInt32) AllocateClearMemory( sizeof(BTreeExtensionsRec) );			// allocate space for our BTCB extensions
-	if ( btcb->refCon == (UInt32)nil ) {
+	btcb->refCon = AllocateClearMemory( sizeof(BTreeExtensionsRec) );			// allocate space for our BTCB extensions
+	if ( btcb->refCon == nil ) {
 		err = R_NoMem;
 		goto exit;
 	}
@@ -1760,8 +1760,8 @@
 	//
 	//	set up our DFA extended BTCB area.  Will we have enough memory on all HFS+ volumes.
 	//
-	btcb->refCon = (UInt32) AllocateClearMemory( sizeof(BTreeExtensionsRec) );			// allocate space for our BTCB extensions
-	if ( btcb->refCon == (UInt32)nil ) {
+	btcb->refCon = AllocateClearMemory( sizeof(BTreeExtensionsRec) );			// allocate space for our BTCB extensions
+	if ( btcb->refCon == nil ) {
 		err = R_NoMem;
 		goto exit;
 	}
@@ -1774,7 +1774,7 @@
 	}
 	else
 	{
-		if ( btcb->refCon == (UInt32)nil ) {
+		if ( btcb->refCon == nil ) {
 			err = R_NoMem;
 			goto exit;
 		}
Index: hfsprogs-332.14/fsck_hfs.tproj/dfalib/BTreePrivate.h
===================================================================
--- hfsprogs-332.14.orig/fsck_hfs.tproj/dfalib/BTreePrivate.h	2008-05-24 14:02:04.000000000 +0200
+++ hfsprogs-332.14/fsck_hfs.tproj/dfalib/BTreePrivate.h	2008-05-24 14:02:06.000000000 +0200
@@ -104,6 +104,9 @@
 
 ///////////////////////////////////// Types /////////////////////////////////////
 
+// Forward declaration from Scavenger.h
+struct BTreeExtensionsRec;
+
 typedef struct BTreeControlBlock {					// fields specific to BTree CBs
 
 	UInt8		keyCompareType;   /* Key string Comparison Type */
@@ -144,7 +147,7 @@
 	UInt32						 numPossibleHints;	// Looks like a formated hint
 	UInt32						 numValidHints;		// Hint used to find correct record.
 	
-	UInt32						 refCon;			//	Used by DFA to point to private data.
+	struct BTreeExtensionsRec			*refCon;			//	Used by DFA to point to private data.
 	SFCB						*fcbPtr;		// fcb of btree file
 	
 } BTreeControlBlock, *BTreeControlBlockPtr;
Index: hfsprogs-332.14/fsck_hfs.tproj/dfalib/hfs_endian.c
===================================================================
--- hfsprogs-332.14.orig/fsck_hfs.tproj/dfalib/hfs_endian.c	2008-05-24 14:02:06.000000000 +0200
+++ hfsprogs-332.14/fsck_hfs.tproj/dfalib/hfs_endian.c	2008-05-24 14:02:19.000000000 +0200
@@ -437,7 +437,7 @@
     BTNodeDescriptor *srcDesc = src->buffer;
     UInt16 *srcOffs = (UInt16 *)((char *)src->buffer + (src->blockSize - (srcDesc->numRecords * sizeof (UInt16))));
 	char *nextRecord;	/*  Points to start of record following current one */
-    UInt32 i;
+    int i;
     UInt32 j;
 
     if (fileID == kHFSExtentsFileID) {

Reply via email to