The following commit has been merged in the master branch: commit 5b65ce7632ab1c16c5f2790da9d9e1b1fdad79bc Author: Simon Wunderlich siwu@hrz.tu-chemnitz.de Date: Wed Mar 28 13:17:46 2007 +0200
- review bitarray integer overflow
diff --git a/batman.h b/batman.h index 74fa7b3..c383b6c 100644 --- a/batman.h +++ b/batman.h @@ -96,7 +96,7 @@ extern char *gw2string[]; struct packet { uint32_t orig; - uint8_t flags; /* 0xF0: UNIDIRECTIONAL link, 0x80: DIRECTLINK flag, ... */ + uint8_t flags; /* 0x80: UNIDIRECTIONAL link, 0x40: DIRECTLINK flag, ... */ uint8_t ttl; uint16_t seqno; uint8_t gwflags; /* flags related to gateway functions: gateway class */ diff --git a/bitarray.c b/bitarray.c index 0ed6b8a..0fd860a 100644 --- a/bitarray.c +++ b/bitarray.c @@ -21,7 +21,7 @@
#include <stdio.h> /* printf() */
-#include "batman-specific.h" +#include "bitarray.h" #include "os.h"
@@ -40,9 +40,10 @@ void bit_init( TYPE_OF_WORD *seq_bits ) { uint8_t get_bit_status( TYPE_OF_WORD *seq_bits, uint16_t last_seqno, uint16_t curr_seqno ) {
int word_offset,word_num; -//TBD: not shure for wrap arounds, what about: if ( curr_seqno - last_seqno > 0 || curr_seqno - last_seqno < - if ( curr_seqno > last_seqno || curr_seqno < last_seqno - SEQ_RANGE ) { - + int16_t diff; + + diff= last_seqno- curr_seqno; + if ( diff < 0 || diff >= SEQ_RANGE ) { return 0;
} else { @@ -142,7 +143,7 @@ void bit_shift( TYPE_OF_WORD *seq_bits, int32_t n ) {
/* receive and process one packet, returns 1 if received seq_num is considered new, 0 if old */ -char bit_get_packet( TYPE_OF_WORD *seq_bits, int32_t seq_num_diff, int8_t set_mark ) { +char bit_get_packet( TYPE_OF_WORD *seq_bits, int16_t seq_num_diff, int8_t set_mark ) {
int i;
diff --git a/bitarray.h b/bitarray.h index 3a02bd9..78141b8 100644 --- a/bitarray.h +++ b/bitarray.h @@ -21,6 +21,7 @@
#define TYPE_OF_WORD unsigned long /* you should choose something big, if you don't want to waste cpu */ #define WORD_BIT_SIZE ( sizeof(TYPE_OF_WORD) * 8 ) +#include "batman-specific.h"
@@ -29,6 +30,6 @@ uint8_t get_bit_status( TYPE_OF_WORD *seq_bits, uint16_t last_seqno, uint16_t cu char *bit_print( TYPE_OF_WORD *seq_bits ); void bit_mark( TYPE_OF_WORD *seq_bits, int32_t n ); void bit_shift( TYPE_OF_WORD *seq_bits, int32_t n ); -char bit_get_packet( TYPE_OF_WORD *seq_bits, int32_t seq_num_diff, int8_t set_mark ); +char bit_get_packet( TYPE_OF_WORD *seq_bits, int16_t seq_num_diff, int8_t set_mark ); int bit_packet_count( TYPE_OF_WORD *seq_bits );