Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

trunk: test_P2N_invalidInput & test_getHostByAddr in IP.test.php fail #2359

Closed
julienmoumne opened this issue Apr 25, 2011 · 16 comments
Closed
Labels
Bug For errors / faults / flaws / inconsistencies etc. Critical Indicates the severity of an issue is very critical and the issue has a very high priority.
Milestone

Comments

@julienmoumne
Copy link
Member

With my box (PHP 5.3.5, HTTPD 2.2), in test_P2N_invalidInput

inet_pton('07.07.07.07');

returns

\u0007\u0007\u0007\u0007

instead of expected

\x00\x00\x00\x00

In test_getHostByAddr, both

Piwik_IP::getHostByAddr('127.0.0.1')
Piwik_IP::getHostByAddr('::1')

return the name of my computer: ju-PC

@robocoder
Copy link
Contributor

Is that on Windows?

@julienmoumne
Copy link
Member Author

I should have mentioned it, it's on Windows 7 x64

@mattab
Copy link
Member

mattab commented Apr 26, 2011

On Windows XP 32bits, I get many errors:|

Fail: D:\piwik\svn\trunk/tests/core/IP.test.php -> Test_Piwik_IP -> test_P2N -> 255.255.255.255 at [D:\piwik\svn\trunk\tests\core\IP.test.php line 120]
Fail: D:\piwik\svn\trunk/tests/core/IP.test.php -> Test_Piwik_IP -> test_P2N -> ::ffff:127.0.0.1 at [D:\piwik\svn\trunk\tests\core\IP.test.php line 120]
Fail: D:\piwik\svn\trunk/tests/core/IP.test.php -> Test_Piwik_IP -> test_P2N_invalidInput -> 07.07.07.07 at [D:\piwik\svn\trunk\tests\core\IP.test.php line 148]
Fail: D:\piwik\svn\trunk/tests/core/IP.test.php -> Test_Piwik_IP -> test_N2P -> ::ffff:127.0.0.1 vs::ffff:7f00:1 at [D:\piwik\svn\trunk\tests\core\IP.test.php line 182]
Fail: D:\piwik\svn\trunk/tests/core/IP.test.php -> Test_Piwik_IP -> test_N2P -> 2001:5c0:1000:b::90f8 vs2001:5c0:1000:0b::90f8 at [D:\piwik\svn\trunk\tests\core\IP.test.php line 182]
Fail: D:\piwik\svn\trunk/tests/core/IP.test.php -> Test_Piwik_IP -> test_prettyPrint -> ::ffff:127.0.0.1 vs::ffff:7f00:1 at [D:\piwik\svn\trunk\tests\core\IP.test.php line 198]
Fail: D:\piwik\svn\trunk/tests/core/IP.test.php -> Test_Piwik_IP -> test_prettyPrint -> 2001:5c0:1000:b::90f8 vs2001:5c0:1000:0b::90f8 at [D:\piwik\svn\trunk\tests\core\IP.test.php line 198]
Fail: D:\piwik\svn\trunk/tests/core/IP.test.php -> Test_Piwik_IP -> test_getIpsForRange -> ::ffff:127.0.0.1/120 at [D:\piwik\svn\trunk\tests\core\IP.test.php line 288]
Fail: D:\piwik\svn\trunk/tests/core/IP.test.php -> Test_Piwik_IP -> test_isIpInRange -> ::ffff:c0a8:010a in ::ffff:192.168.1.10 at [D:\piwik\svn\trunk\tests\core\IP.test.php line 384]
Fail: D:\piwik\svn\trunk/tests/core/IP.test.php -> Test_Piwik_IP -> test_isIpInRange -> ::ffff:c0a8:010a in ::ffff:192.168.1.10 at [D:\piwik\svn\trunk\tests\core\IP.test.php line 390]
Fail: D:\piwik\svn\trunk/tests/core/IP.test.php -> Test_Piwik_IP -> test_isIpInRange -> 0000:0000:0000:0000:0000:ffff:c0a8:010a in ::ffff:192.168.1.10 at [D:\piwik\svn\trunk\tests\core\IP.test.php line 384]
Fail: D:\piwik\svn\trunk/tests/core/IP.test.php -> Test_Piwik_IP -> test_isIpInRange -> 0000:0000:0000:0000:0000:ffff:c0a8:010a in ::ffff:192.168.1.10 at [D:\piwik\svn\trunk\tests\core\IP.test.php line 390]
Fail: D:\piwik\svn\trunk/tests/core/IP.test.php -> Test_Piwik_IP -> test_getHostByAddr -> ::1 -> ip6-localhost at [D:\piwik\svn\trunk\tests\core\IP.test.php line 497]
Exception: D:\piwik\svn\trunk/tests/core/IP.test.php -> Test_Piwik_IP -> test_getHostByAddr -> Unexpected PHP error [gethostbyaddr() [<a href='function.gethostbyaddr'>function.gethostbyaddr</a>]: Address is not in a.b.c.d form] severity [E_WARNING] in [D:\piwik\svn\trunk\core\IP.php line 384]

Good that we have unit tests to find these out ;)

@robocoder
Copy link
Contributor

Matt: is that php 5.2.6? (just making sure because pre-5.3 uses the compat functions).

@mattab
Copy link
Member

mattab commented Apr 26, 2011

Yes I am running 5.2.6 - if it's too difficult / not possible to have ipv6 on pre 5.3, I think it's reasonnable, but we need to clarify it and fail gracefully (not sure what it would mean?)

@mattab
Copy link
Member

mattab commented Apr 26, 2011

When I generate a new visit on windows 5.2.6, with debug on, I see in the piwik.php output:

 New Visit (IP = 0.0.0.0) ```


then below I see

'location_ip' => '�' . "\0" . '' . "\0" . '�', ```

quite interesting ;)

@robocoder
Copy link
Contributor

thanks. i will fix this today.

@robocoder
Copy link
Contributor

(In [4564]) fixes #2359 - note: on Windows with php 5.1.x/5.2.x, gethostbyaddr() doesn't work with ipv6 addresses

@mattab
Copy link
Member

mattab commented Apr 26, 2011

Thanks for fixing tests. There is still an issue, that on pre 5.3, ipv4 is not supported anymore. Is it possible that we leave the ipv4 address as is somehow?

for example, I try:


Index: piwik.php
===================================================================
--- piwik.php   (revision 4564)
+++ piwik.php   (working copy)
@@ -8,9 +8,10 @@
  *
  * @package Piwik
  */
-$GLOBALS['PIWIK_TRACKER_DEBUG'] = false;
+$GLOBALS['PIWIK_TRACKER_DEBUG'] = !false;
 $GLOBALS['PIWIK_TRACKER_DEBUG_FORCE_SCHEDULED_TASKS'] = false;
 define('PIWIK_ENABLE_TRACKING', true);
+$_SERVER['REMOTE_ADDR'] = '201.29.95.170';

 if(file_exists('bootstrap.php'))
 {

And, this shows in output: New Visit (IP = 0.0.0.0)

Is it possible, that ipv4 IPs are compatible with new code, so as to not introduce regression?

@robocoder
Copy link
Contributor

(In [4565]) fixes #2359 - looks like this debug statement was added while I was working in my own branch

@robocoder
Copy link
Contributor

re: comment:10 -- I did a grep and didn't find any other lingering long2ip/ip2long calls that shouldn't be there.

@robocoder
Copy link
Contributor

(In [4566]) refs #2359 - catch more edge cases as errors

@robocoder
Copy link
Contributor

(In [4567]) refs #2359 - relax some of the rules for compatibility with native function

@robocoder
Copy link
Contributor

(In [4570]) refs #2359 - clean up php_compat_inet_pton

@julienmoumne
Copy link
Member Author

I have two minor failing tests in test_getHostByAddr().

@php_uname('n')

returns the name of my machine with capital letters :

JU-PC

instead of what's displayed if I press Windows + Pause :

ju-PC

However,

Piwik_IP::getHostByAddr('127.0.0.1')

correctly returns

ju-PC

failing both asserts.

@robocoder
Copy link
Contributor

(In [4621]) refs #2359 - thanks Julien

@julienmoumne julienmoumne added this to the 1.4 - Piwik 1.4 milestone Jul 8, 2014
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug For errors / faults / flaws / inconsistencies etc. Critical Indicates the severity of an issue is very critical and the issue has a very high priority.
Projects
None yet
Development

No branches or pull requests

3 participants