Skip to content

Commit 8199e84

Browse files
committed
IfIndex from snmp is usually a string, cast inside function
1 parent 2f5e384 commit 8199e84

File tree

3 files changed

+8
-7
lines changed

3 files changed

+8
-7
lines changed

LibreNMS/Cache/Port.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public function get(int $port_id): ?\App\Models\Port
4141
* Get a port from an ifIndex.
4242
* Must be constrained to a device, when $device is null, use primary device
4343
*/
44-
public function getByIfIndex(int $ifIndex, \App\Models\Device|int|null $device = null): ?\App\Models\Port
44+
public function getByIfIndex(int|string|null $ifIndex, \App\Models\Device|int|null $device = null): ?\App\Models\Port
4545
{
4646
return $this->get((int) $this->getIdFromIfIndex($ifIndex, $device));
4747
}
@@ -59,9 +59,10 @@ public function getByIfName(string $ifName, \App\Models\Device|int|null $device
5959
* Get a port_id from an ifIndex.
6060
* Must be constrained to a device, when $device is null, use primary device
6161
*/
62-
public function getIdFromIfIndex(int $ifIndex, \App\Models\Device|int|null $device = null): ?int
62+
public function getIdFromIfIndex(int|string|null $ifIndex, \App\Models\Device|int|null $device = null): ?int
6363
{
6464
$device_id = $this->deviceToId($device);
65+
$ifIndex = (int) $ifIndex;
6566

6667
if (! array_key_exists($device_id, $this->ifIndexMaps)) {
6768
$this->ifIndexMaps[$device_id] = \App\Models\Port::where('device_id', $device_id)->pluck('port_id', 'ifIndex')->all();

LibreNMS/OS/Shared/Cisco.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -469,7 +469,7 @@ public function pollNac()
469469
$mac_address = strtolower(implode(array_map('zeropad', explode(':', $portAuthSessionEntryParameters['cafSessionClientMacAddress'] ?? null))));
470470

471471
$nac->put($mac_address, new PortsNac([
472-
'port_id' => (int) PortCache::getIdFromIfIndex((int) $ifIndex, $this->getDevice()),
472+
'port_id' => (int) PortCache::getIdFromIfIndex($ifIndex, $this->getDevice()),
473473
'mac_address' => $mac_address,
474474
'auth_id' => $auth_id,
475475
'domain' => $portAuthSessionEntryParameters['cafSessionDomain'] ?? '',
@@ -695,7 +695,7 @@ public function discoverTransceivers(): Collection
695695
$ifIndex = $ent['ifIndex'] ?? null;
696696

697697
return new Transceiver([
698-
'port_id' => (int) PortCache::getIdFromIfIndex((int) $ifIndex, $this->getDevice()),
698+
'port_id' => (int) PortCache::getIdFromIfIndex($ifIndex, $this->getDevice()),
699699
'index' => $index,
700700
'type' => $ent['entPhysicalDescr'] ?? null,
701701
'vendor' => $ent['entPhysicalMfgName'] ?? null,
@@ -783,7 +783,7 @@ public function discoverQos(): Collection
783783

784784
$qos->push(new Qos([
785785
'device_id' => $this->getDeviceId(),
786-
'port_id' => $parent ? null : PortCache::getIdFromIfIndex((int) $servicePolicies[$policyId]['cbQosIfIndex'], $this->getDevice()),
786+
'port_id' => $parent ? null : PortCache::getIdFromIfIndex($servicePolicies[$policyId]['cbQosIfIndex'], $this->getDevice()),
787787
'type' => $dbtype,
788788
'title' => $title,
789789
'tooltip' => $tooltip,

includes/html/pages/device/edit/snmp.inc.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
$device->features = null;
3939
$device->hardware = $_POST['hardware'];
4040
$device->icon = null;
41-
$device->os = $_POST['os'] ? $_POST['os_id'] : 'ping';
41+
$device->os = $_POST['os'] ? strip_tags($_POST['os_id']) : 'ping';
4242
$device->snmp_disable = 1;
4343
$device->sysName = $_POST['sysName'] ?: null;
4444
$device->version = null;
@@ -211,7 +211,7 @@
211211
<label for='os' class='col-sm-2 control-label'>OS (optional)</label>
212212
<div class='col-sm-4'>
213213
<input id='os' class='form-control' name='os' value='" . htmlspecialchars(Config::get("os.{$device->os}.text")) . "'/>
214-
<input type='hidden' id='os_id' class='form-control' name='os_id' value='" . $device->os . "'/>
214+
<input type='hidden' id='os_id' class='form-control' name='os_id' value='" . htmlspecialchars($string)->os . "'/>
215215
</div>
216216
</div>
217217
</div>

0 commit comments

Comments
 (0)