Skip to content

Commit e2d6639

Browse files
committed
IfIndex from snmp is usually a string, cast inside function
1 parent 6de7ccd commit e2d6639

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
@@ -470,7 +470,7 @@ public function pollNac()
470470
$mac_address = Mac::parse($portAuthSessionEntryParameters['cafSessionClientMacAddress'])->hex();
471471

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

698698
return new Transceiver([
699-
'port_id' => (int) PortCache::getIdFromIfIndex((int) $ifIndex, $this->getDevice()),
699+
'port_id' => (int) PortCache::getIdFromIfIndex($ifIndex, $this->getDevice()),
700700
'index' => $index,
701701
'type' => $ent['entPhysicalDescr'] ?? null,
702702
'vendor' => $ent['entPhysicalMfgName'] ?? null,
@@ -784,7 +784,7 @@ public function discoverQos(): Collection
784784

785785
$qos->push(new Qos([
786786
'device_id' => $this->getDeviceId(),
787-
'port_id' => $parent ? null : PortCache::getIdFromIfIndex((int) $servicePolicies[$policyId]['cbQosIfIndex'], $this->getDevice()),
787+
'port_id' => $parent ? null : PortCache::getIdFromIfIndex($servicePolicies[$policyId]['cbQosIfIndex'], $this->getDevice()),
788788
'type' => $dbtype,
789789
'title' => $title,
790790
'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)