MyBB Community Forums

Full Version: Search for Users with IP-Range in ModCP can never have results
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi!

Short description:

When searching for an IP-Range in ModCP there will never be any "user results", only posts.

Long description:

Today I stumbled upon a bug with the IP-Search feature in the ModCP. Whenever I enter an IP-Range as the search parameter (e.g. 123.123.123.*), the search will never return any users. Even if there is a user with regIp or lastIp 123.123.123.123 that can be found by only searching for 123.123.123.123

The problem lies within the code of modcp.php close to line ~3700:

if(is_array($ip_range))
 {
 if(strcmp($ip_range[0], $ipaddress['regip']) >= 0 && strcmp($ip_range[1], $ipaddress['regip']) <= 0)
 {
 eval("\$subject = \"".$templates->get("modcp_ipsearch_result_regip")."\";");
 $ip = my_inet_ntop($db->unescape_binary($ipaddress['regip']));
 }
 elseif(strcmp($ip_range[0], $ipaddress['lastip']) >= 0 && strcmp($ip_range[1], $ipaddress['lastip']) <= 0)
 {
 eval("\$subject = \"".$templates->get("modcp_ipsearch_result_lastip")."\";");
 $ip = my_inet_ntop($db->unescape_binary($ipaddress['lastip']));
 }
 }

The if's with the "strcmp" will never return true, because they basically do (for my example from above):

if(123.123.123.0 >= 123.123.123.123 && 123.123.123.255 <= 123.123.123.123)

which can't ever evaluate to true.


MyBB Version:

I'm using the newest version of MyBB, which is currently 1.8.3.

The bug was introduced to 1.8 when the IPv6 support was added last year, but I guess nobody noticed it because that feature isn't used very often.

Possible fix:

The bug can be fixed by switching ">=" with "<=" and vice versa everywhere in the code snippet above. Alternatively switch the 0 and 1 indexes around in the $ip_range[] arrays. Or changing the order of the parameters for the strcmp methods.

I chose to go with the first solution and the search now works correctly for my forum, resulting in matching users found by regIp and lastIp when searching by IP-Range.
I've opened a pull request for this bug, just in case: https://github.com/mybb/mybb/pull/1678/
Hi,

Thank you for your report. We have pushed this issue to our Github repository for further analysis where you can track our commits and progress with fixing this bug. Discussions regarding this bug may also take place there too.

Follow this link to visit the issue on Github: https://github.com/mybb/mybb/issues/1695

Thanks for contributing to MyBB!

Regards,
The MyBB Group