tags 484295 patch
thanks

Yuckety.  There wasn't much of any NULL pointer checking or anything in
this code.  The segfaults were caused by vlanprintelem() trying to dump
the contents of vlant[vlan].table for non-existing VLANs.  This should
of course never happen, but when it did a simple test for
vlant[vlan].table == NULL could have easily made it into an error
message instead of a segfault.

Well, I'm not going to fix all that now, given that there must be
hundreds of places to add such tests all over the place.

The main reason why everything went wrong on 64bit systems were lots of
type mismatches in bitarray.h.  Among the more serious was BAC_SET using
a signed int as temporary storage for bitarray elemens, causing
interesting effects if you happened to set bit 31, e.g. by creating VLAN
31...

There were also a number of attempts to shift 1 more than 31 bits to the
left, which doesn't really work well.

The attached patch fixes these important parts and stabilizes vde_switch
on my system.  Please consider applying it before lenny is released.

Thanks,
Bjørn

--- ../vde2-2.2.0-pre2.orig/bitarray.h	2007-11-09 14:36:41.000000000 +0100
+++ vde2-2.2.0-pre2/bitarray.h	2008-06-04 13:24:43.000000000 +0200
@@ -94,14 +94,14 @@
 	 if(nb != NULL) \
 	 for(__i=__WORDSIZEROUND(N);__i<__WORDSIZEROUND(M);__i++) \
 	 nb[__i]=0; \
-	 nb[__WORDSIZEROUND(N)-1] &= (1<<(((((N)&__WORDSIZEMASK)-1)&0x1f)+1))-1; \
+	 nb[__WORDSIZEROUND(N)-1] &= (1L<<(((((N)&__WORDSIZEMASK)-1)&0x1f)+1))-1; \
 	 nb;})
 
-#define BA_CHECK(X,I) ((X) && ((X)[(I)>>__LOG_WORDSIZE] & (1 << ((I) & __WORDSIZEMASK)))) 
+#define BA_CHECK(X,I) ((X) && ((X)[(I)>>__LOG_WORDSIZE] & (1L << ((I) & __WORDSIZEMASK)))) 
 
-#define BA_SET(X,I) ((X)[(I)>>__LOG_WORDSIZE] |= (1 << ((I) & __WORDSIZEMASK)))
+#define BA_SET(X,I) ((X)[(I)>>__LOG_WORDSIZE] |= (1L << ((I) & __WORDSIZEMASK)))
 
-#define BA_CLR(X,I) ((X)[(I)>>__LOG_WORDSIZE] &= ~(1 << ((I) & __WORDSIZEMASK)))
+#define BA_CLR(X,I) ((X)[(I)>>__LOG_WORDSIZE] &= ~(1L << ((I) & __WORDSIZEMASK)))
 
 #define BA_ZAP(X,N) \
 	({ register unsigned int __i; \
@@ -159,7 +159,7 @@
 	 int max=__WORDSIZEROUND(N); \
 	 for (__i=0; __i< max; __i++) \
 	 (DST)[__i] &= ~((SRC)[__i]); \
-	 nb[max-1] &= (1<<(((((N)&__WORDSIZEMASK)-1)&0x1f)+1))-1; \
+	 nb[max-1] &= (1L<<(((((N)&__WORDSIZEMASK)-1)&0x1f)+1))-1; \
 	 0; })
 
 #define BA_NEGATE(X,N) \
@@ -167,7 +167,7 @@
 	 int max=__WORDSIZEROUND(N); \
 	 for (__i=0; __i< max; __i++) \
 	 (X)[__i] = ~((X)[__i]); \
-	 nb[max-1] &= (1<<(((((N)&__WORDSIZEMASK)-1)&0x1f)+1))-1; \
+	 nb[max-1] &= (1L<<(((((N)&__WORDSIZEMASK)-1)&0x1f)+1))-1; \
 	 0; })
 
 /* Bit Array with Cardinality (Count of set bit) */
@@ -183,23 +183,23 @@
 	 (B)[__WORDSIZEROUND(M)]=__size; \
 	 for(__i=__WORDSIZEROUND(N);__i<__WORDSIZEROUND(M);__i++) \
 	 nb[__i]=0; }\
-	 nb[__WORDSIZEROUND(N)-1] &= (1<<(((((N)&__WORDSIZEMASK)-1)&0x1f)+1))-1; \
+	 nb[__WORDSIZEROUND(N)-1] &= (1L<<(((((N)&__WORDSIZEMASK)-1)&0x1f)+1))-1; \
 	 nb;})
 
 /* BA_CHECK and BAC_CHECK are the same */
-#define BAC_CHECK(X,I) ((X) && ((X)[(I)>>__LOG_WORDSIZE] & (1 << ((I) & __WORDSIZEMASK))))
+#define BAC_CHECK(X,I) ((X) && ((X)[(I)>>__LOG_WORDSIZE] & (1L << ((I) & __WORDSIZEMASK))))
 
 #define BAC_SET(X,N,I) \
-	({ register int __v=(X)[(I)>>__LOG_WORDSIZE]; \
-		register int __w=__v; \
-		__v |= (1 << ((I) & __WORDSIZEMASK)); \
+	({ register bitarrayelem __v=(X)[(I)>>__LOG_WORDSIZE]; \
+		register bitarrayelem __w=__v; \
+		__v |= (1L << ((I) & __WORDSIZEMASK)); \
 		if (__v != __w) (X)[(I)>>__LOG_WORDSIZE]=__v,((X)[__WORDSIZEROUND(N)]++); \
 		})
 
 #define BAC_CLR(X,N,I) \
-	({ register int __v=(X)[(I)>>__LOG_WORDSIZE]; \
-	 register int __w=__v; \
-	 __v &= ~(1 << ((I) & __WORDSIZEMASK)); \
+	({ register bitarrayelem __v=(X)[(I)>>__LOG_WORDSIZE]; \
+	 register bitarrayelem __w=__v; \
+	 __v &= ~(1L << ((I) & __WORDSIZEMASK)); \
 	 if (__v != __w) (X)[(I)>>__LOG_WORDSIZE]=__v,((X)[__WORDSIZEROUND(N)]--); \
 	 })
 

Reply via email to