bmx6 icon indicating copy to clipboard operation
bmx6 copied to clipboard

Endianness in the is_ip_valid() function

Open lese123 opened this issue 4 years ago • 0 comments

Line 603 of the is_ip_valid function in the ip.c file:

                if (ipXto4(*ip) != INADDR_LOOPBACK && ipXto4(*ip) != INADDR_NONE)
                        return YES;

It only works on a big endian device. On a little endian device, ipXto4(*ip) of a loopback device has the value 0x100007f while INADDR_LOOPBACK has the value 0x7f000001.

Should we use something like htonl' to convert IP addresses from host order to network order before the comparison?

Also on line 592, for an IPv6 loopback address ::1, is_zero((void*) ip, sizeof ( IPX_T) - sizeof (IP4_T) always evaluates TRUE but family is AF_INET6, so the condition (family != (is_zero((void*) ip, sizeof ( IPX_T) - sizeof (IP4_T)) ? AF_INET : AF_INET6) is alway TRUE. Line 595 to 598 will always be skipped.

lese123 avatar Aug 14 '20 03:08 lese123