Project

General

Profile

Actions

Bug #2956

closed

lookup_gateway_ip_by_name() (in gwlb.inc) might return the wrong IP if the gateway has an entirely numeric name

Added by Kim Johnsson over 8 years ago. Updated over 8 years ago.

Status:
Resolved
Priority:
Normal
Assignee:
-
Category:
Gateways
Target version:
Start date:
04/18/2013
Due date:
% Done:

100%

Estimated time:
Plus Target Version:
Release Notes:
Affected Version:
All
Affected Architecture:

Description

I have two gateways, named "1812" and "1812v6", with "1812" being first in the list. When this function is called asking for the IP of "1812v6", the IP for "1812" is returned. This seems to be because PHP is being clever and treating $gname in this code as an integer, and thus converting $name to an integer in the comparison ("1812v6" gets converted to 1812, which matches the wrong gateway):

function lookup_gateway_ip_by_name($name) {
        $gateways_arr = return_gateways_array(false, true);
        foreach ($gateways_arr as $gname => $gw) {
                if ($gw['name'] == $name || $gname == $name)
                        return $gw['gateway'];
        }

        return false;
}

The following change seems to force a string comparison (which is what you want to do):
-                if ($gw['name'] == $name || $gname == $name)
+                if ($gw['name'] == "$name" || "$gname" == "$name")

Might wanna double-check that though, I try to avoid PHP these days because of stupidities like that.

Actions #1

Updated by Chris Buechler over 8 years ago

  • Category changed from Web Interface to Gateways
  • Target version set to 2.1
Actions #2

Updated by Renato Botelho over 8 years ago

  • Status changed from New to Feedback
  • % Done changed from 0 to 100
Actions #4

Updated by Renato Botelho over 8 years ago

  • Status changed from Feedback to Resolved
Actions

Also available in: Atom PDF