bug in masked_match function

Andrew Bird Andrew.Bird at goodrich.com
Fri Mar 28 14:52:17 GMT 2003


Tomoki
    I think the right solution is to revert the patch - i've knocked up
the following test program.

testbox$ ./a.out
255.255.254.0 == addr/23
1111 1111 1111 1111 1111 1110 0000 0000

Reverting old change - correct
(ALLONES >> atoi(slash + 1)) ^ ALLONES
1111 1111 1111 1111 1111 1110 0000 0000

changing XOR to AND is incorrect
(ALLONES << atoi(slash + 1)) & ALLONES
1111 1111 1000 0000 0000 0000 0000 0000



Best Regards



Andrew Bird (Unix Consultant)



#define ALLONES  ((uint32)0xFFFFFFFF)

typedef unsigned int uint32;


print_uint32(uint32 val) {
   int i;
   for (i = 31 ; i >= 0 ;i--) {
       printf("%c", val & (1 << i) ? '1' : '0');
       if( (i % 4) == 0 )
          printf(" ");
   }
   printf("\n\n");
}


int main() {

    char *string="10.0.0.0/23";

    char *slash="/23";

    uint32 mask;

    mask =(255<<24) + (255<<16) + (254<<8) + 0;
    printf("255.255.254.0 == addr/23\n");
    print_uint32(mask);

    mask = (uint32)((ALLONES >> atoi(slash + 1)) ^ ALLONES);
    printf("Reverting old change - correct\n");
    printf("(ALLONES >> atoi(slash + 1)) ^ ALLONES\n");
    print_uint32(mask);


    mask = (uint32)((ALLONES << atoi(slash + 1)) & ALLONES);
    printf("changing XOR to AND is incorrect\n");
    printf("(ALLONES << atoi(slash + 1)) & ALLONES\n");
    print_uint32(mask);

}





More information about the samba-technical mailing list