Project

General

Profile

« Previous | Next » 

Revision 366de107

Added by Stilez y over 9 years ago

data sanitising: ip2long32, ip2ulong, long2ip32 (FIXED RESUBMIT of #2152)

Self explanatory. If these functions find themselves trying to convert non-int data (or an x64 int with non-zeros in any bits >32) to dotted IPv4, or non-dotted IPv4 to integer IPv4 values, something's wrong and they shouldn't return a value that looks like they succeeded.

The original PR caused issues with VPN. This was because, to check the presence of any bits beyond #32 were zero (if INT was 64 bits or larger), the operator >>32 was used. Unfortunately this was undefined on x32 platforms. (See https://forum.pfsense.org/index.php?topic=104175 ).

The fix below was tested on x32, on the same thread.

TEST PR'ed IN #2152 (FAILS ON x32):
return ((is_int($ip) && ($ip >> 32) 0) ? long2ip($ip & 0xFFFFFFFF) : '');

TEST NOW USED (SEEMS RELIABLE ON ALL SYSTEM INT SIZES):
return ((is_int($ip) && ($ip & ~0xFFFFFFFF) 0) ? long2ip($ip & 0xFFFFFFFF) : '');

Other than this line and a comment, this code is identical to PR #2152

  • added
  • modified
  • copied
  • renamed
  • deleted