From ddc987e23c7ed3242b7ba92f475b3da12a7cec8e Mon Sep 17 00:00:00 2001 From: Franco Fichtner Date: Mon, 30 Nov 2015 09:30:44 +0100 Subject: [PATCH] interfaces: fix a (mildy amusing) crash report --- src/etc/inc/interfaces.inc | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/src/etc/inc/interfaces.inc b/src/etc/inc/interfaces.inc index 1fb2c5460..dee287524 100644 --- a/src/etc/inc/interfaces.inc +++ b/src/etc/inc/interfaces.inc @@ -3995,34 +3995,38 @@ function convert_friendly_interface_to_real_interface_name($interface) { return get_real_interface($interface); } -/* - * convert_real_interface_to_friendly_interface_name($interface): convert fxp0 -> wan, etc. - */ -function convert_real_interface_to_friendly_interface_name($interface = "wan") { +/* convert fxp0 -> wan, etc. */ +function convert_real_interface_to_friendly_interface_name($interface = 'wan') +{ global $config; - /* XXX: For speed reasons reference directly the interface array */ - $ifdescrs = &$config['interfaces']; - //$ifdescrs = get_configured_interface_list(false, true); + if (!isset($config['interfaces'])) { + /* some people do trigger this, I don't know why :) */ + return NULL; + } - foreach ($ifdescrs as $if => $ifname) { - if ($if == $interface || $ifname['if'] == $interface) + foreach ($config['interfaces'] as $if => $ifname) { + if ($if == $interface || $ifname['if'] == $interface) { return $if; + } - if (get_real_interface($if) == $interface) + if (get_real_interface($if) == $interface) { return $if; + } $int = get_parent_interface($if, true); if (is_array($int)) { foreach ($int as $iface) { - if ($iface == $interface) + if ($iface == $interface) { return $if; + } } } } - if ($interface == "enc0") + if ($interface == 'enc0') { return 'IPsec'; + } return NULL; }