Details
-
Type:
Bug
-
Status:
Closed
-
Priority:
Minor
-
Resolution: Fixed
-
Affects Version/s: 1.9.1
-
Component/s: Quiz
-
Labels:None
-
Environment:64 bit CPU architecture - Linux Intel
-
Affected Branches:MOODLE_19_STABLE
-
Fixed Branches:MOODLE_17_STABLE, MOODLE_18_STABLE, MOODLE_19_STABLE
Description
When using quiz restriction by ip address, using range type 1: xxx.xxx.xxx.xxx/xx, on 64 bit CPU, result is unexpected. Add the '+' line :
+++ lib/moodlelib.php
@@ -7029,6 +7029,7 @@
if (strpos($subnet, '/') !== false) { /// type 1
list($ip, $mask) = explode('/', $subnet);
$mask = 0xffffffff << (32 - $mask);
+ $mask = substr($mask,0,8); // Compatib. cpu 64 bit
$found = ((ip2long($addr) & $mask) == (ip2long($ip) & $mask));
} else if (strpos($subnet, '-') !== false) {/// type 3
$subnetparts = explode('.', $subnet);
Thank you very much for reporting this issues, especially since you included a suggested fix. I'm sorry it took me so long to get around to looking at it.
Before applying your fix, I would like to understand it better. At the moment I am confused. All we are doing with $mask is &ing it with some 32 bit integers, so why should it matter if there are some extra bits set in $mask?
Would it be possible for you to try running the unit tests for this function on your 64-bit CPU? You just need to go to the URL .../admin/report/simpletest/index.php?&path=lib/simpletest/testmoodlelib.php on your moodle server. Do all those tests pass, both with and without your change?
One think about your fix that I don't like is the way it uses string manipulation on $mask. Wouldn't it be better to do $mask = $mask & 0xffffffff; instead of your line of code?