Uploaded image for project: 'phpBB'
  1. phpBB
  2. PHPBB-11765

short_ipv6() doesn't expect IPv4 embedded IPv6 addresses

XMLWordPrintable

    • Icon: Improvement Improvement
    • Resolution: Fixed
    • Icon: Minor Minor
    • 3.3.11
    • 3.1.0-a3
    • Sessions
    • None
    • PHP 5.4.7

      In /includes/functions.php we have function short_ipv6(). It will expand a compressed IPv6 (i.e. from "FADE:BAD::" to "FADE:BAD:0000:0000:0000:0000:0000:0000" in order to be able to return as many words (hexadecatets) as requested.

      However, the expansion will invalidate the address if it's one with an embedded IPv4, i.e. "FADE:BAD::192.168.0.1" will become "FADE:BAD:0000:0000:0000:0000:0000:0000:192.168.0.1".

      The solution is to first check for an IPv4 and replace that with two appropriate words:
      Find

      function short_ipv6($ip, $length)
      {
      	if ($length < 1)
      	{
      		return '';
      	}

      After, add:

      	// IPv6 with embedded IPv4
      	$sOctet= '([0-9]{1,2}|[01][0-9]{2}|2[0-4][0-9]|25[0-5])';
      	if( preg_match( "#$sOctet\\.$sOctet\\.$sOctet\\.$sOctet#", $ip, $aMatch ) ) {
      		$sReplace= sprintf( '%02x%02x:%02x%02x', $aMatch[1], $aMatch[2], $aMatch[3], $aMatch[4] );
      		$ip= str_replace( $aMatch[0], $sReplace, $ip );
      	}

      See http://tools.ietf.org/rfc/rfc6052.txt

            Marc Marc
            AmigoJack AmigoJack
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: