diff --git a/CHANGELOG.md b/CHANGELOG.md index c6fea7a..366df25 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -82,7 +82,8 @@ For major (breaking) changes - **version 4, 3 and 2** - see end of page. | Version | Date | Comment | | ------- | ---------- | --------------------------------------------------------------------------------------------------- | -| 5.17.3 | 2023-01-10 | `processes` fix elapsed time parsing (linux) | +| 5.17.4 | 2023-01-24 | `networkInterfaces()` sanitizing networkInterfaces device names | +| 5.17.3 | 2023-01-10 | `processes()` fix elapsed time parsing (linux) | | 5.17.2 | 2023-01-10 | `utils` fix killing powershell (windows) | | 5.17.1 | 2023-01-06 | `graphics()` positionX, positionY Ventura fix (max OS) | | 5.17.0 | 2023-01-06 | `graphics()` added positionX, positionY (max OS) | diff --git a/docs/history.html b/docs/history.html index 2d3e3ed..06ac25e 100644 --- a/docs/history.html +++ b/docs/history.html @@ -57,6 +57,11 @@ + + 5.17.4 + 2023-01-24 + networkInterfaces() sanitizing interface names + 5.17.3 2023-01-10 diff --git a/docs/index.html b/docs/index.html index a0ba8a0..cd2e243 100644 --- a/docs/index.html +++ b/docs/index.html @@ -170,7 +170,7 @@
systeminformation
 
-
New Version: 5.17.3
+
New Version: 5.17.4
diff --git a/lib/network.js b/lib/network.js index 594128a..adada43 100644 --- a/lib/network.js +++ b/lib/network.js @@ -743,6 +743,14 @@ function networkInterfaces(callback, rescan, defaultString) { }); } + let ifaceSanitized = ''; + const s = util.isPrototypePolluted() ? '---' : util.sanitizeShellString(nic.iface); + for (let i = 0; i <= util.mathMin(s.length, 2000); i++) { + if (s[i] !== undefined) { + ifaceSanitized = ifaceSanitized + s[i]; + } + } + result.push({ iface: nic.iface, ifaceName: nic.iface, @@ -759,7 +767,7 @@ function networkInterfaces(callback, rescan, defaultString) { duplex: nic.duplex, mtu: nic.mtu, speed: nic.speed, - dhcp: getDarwinIfaceDHCPstatus(nic.iface), + dhcp: getDarwinIfaceDHCPstatus(ifaceSanitized), dnsSuffix: '', ieee8021xAuth: '', ieee8021xState: '', @@ -830,37 +838,44 @@ function networkInterfaces(callback, rescan, defaultString) { } }); let iface = dev.split(':')[0].trim().toLowerCase(); - const cmd = `echo -n "addr_assign_type: "; cat /sys/class/net/${iface}/addr_assign_type 2>/dev/null; echo; - echo -n "address: "; cat /sys/class/net/${iface}/address 2>/dev/null; echo; - echo -n "addr_len: "; cat /sys/class/net/${iface}/addr_len 2>/dev/null; echo; - echo -n "broadcast: "; cat /sys/class/net/${iface}/broadcast 2>/dev/null; echo; - echo -n "carrier: "; cat /sys/class/net/${iface}/carrier 2>/dev/null; echo; - echo -n "carrier_changes: "; cat /sys/class/net/${iface}/carrier_changes 2>/dev/null; echo; - echo -n "dev_id: "; cat /sys/class/net/${iface}/dev_id 2>/dev/null; echo; - echo -n "dev_port: "; cat /sys/class/net/${iface}/dev_port 2>/dev/null; echo; - echo -n "dormant: "; cat /sys/class/net/${iface}/dormant 2>/dev/null; echo; - echo -n "duplex: "; cat /sys/class/net/${iface}/duplex 2>/dev/null; echo; - echo -n "flags: "; cat /sys/class/net/${iface}/flags 2>/dev/null; echo; - echo -n "gro_flush_timeout: "; cat /sys/class/net/${iface}/gro_flush_timeout 2>/dev/null; echo; - echo -n "ifalias: "; cat /sys/class/net/${iface}/ifalias 2>/dev/null; echo; - echo -n "ifindex: "; cat /sys/class/net/${iface}/ifindex 2>/dev/null; echo; - echo -n "iflink: "; cat /sys/class/net/${iface}/iflink 2>/dev/null; echo; - echo -n "link_mode: "; cat /sys/class/net/${iface}/link_mode 2>/dev/null; echo; - echo -n "mtu: "; cat /sys/class/net/${iface}/mtu 2>/dev/null; echo; - echo -n "netdev_group: "; cat /sys/class/net/${iface}/netdev_group 2>/dev/null; echo; - echo -n "operstate: "; cat /sys/class/net/${iface}/operstate 2>/dev/null; echo; - echo -n "proto_down: "; cat /sys/class/net/${iface}/proto_down 2>/dev/null; echo; - echo -n "speed: "; cat /sys/class/net/${iface}/speed 2>/dev/null; echo; - echo -n "tx_queue_len: "; cat /sys/class/net/${iface}/tx_queue_len 2>/dev/null; echo; - echo -n "type: "; cat /sys/class/net/${iface}/type 2>/dev/null; echo; - echo -n "wireless: "; cat /proc/net/wireless 2>/dev/null | grep ${iface}; echo; - echo -n "wirelessspeed: "; iw dev ${iface} link 2>&1 | grep bitrate; echo;`; + let ifaceSanitized = ''; + const s = util.isPrototypePolluted() ? '---' : util.sanitizeShellString(iface); + for (let i = 0; i <= util.mathMin(s.length, 2000); i++) { + if (s[i] !== undefined) { + ifaceSanitized = ifaceSanitized + s[i]; + } + } + const cmd = `echo -n "addr_assign_type: "; cat /sys/class/net/${ifaceSanitized}/addr_assign_type 2>/dev/null; echo; + echo -n "address: "; cat /sys/class/net/${ifaceSanitized}/address 2>/dev/null; echo; + echo -n "addr_len: "; cat /sys/class/net/${ifaceSanitized}/addr_len 2>/dev/null; echo; + echo -n "broadcast: "; cat /sys/class/net/${ifaceSanitized}/broadcast 2>/dev/null; echo; + echo -n "carrier: "; cat /sys/class/net/${ifaceSanitized}/carrier 2>/dev/null; echo; + echo -n "carrier_changes: "; cat /sys/class/net/${ifaceSanitized}/carrier_changes 2>/dev/null; echo; + echo -n "dev_id: "; cat /sys/class/net/${ifaceSanitized}/dev_id 2>/dev/null; echo; + echo -n "dev_port: "; cat /sys/class/net/${ifaceSanitized}/dev_port 2>/dev/null; echo; + echo -n "dormant: "; cat /sys/class/net/${ifaceSanitized}/dormant 2>/dev/null; echo; + echo -n "duplex: "; cat /sys/class/net/${ifaceSanitized}/duplex 2>/dev/null; echo; + echo -n "flags: "; cat /sys/class/net/${ifaceSanitized}/flags 2>/dev/null; echo; + echo -n "gro_flush_timeout: "; cat /sys/class/net/${ifaceSanitized}/gro_flush_timeout 2>/dev/null; echo; + echo -n "ifalias: "; cat /sys/class/net/${ifaceSanitized}/ifalias 2>/dev/null; echo; + echo -n "ifindex: "; cat /sys/class/net/${ifaceSanitized}/ifindex 2>/dev/null; echo; + echo -n "iflink: "; cat /sys/class/net/${ifaceSanitized}/iflink 2>/dev/null; echo; + echo -n "link_mode: "; cat /sys/class/net/${ifaceSanitized}/link_mode 2>/dev/null; echo; + echo -n "mtu: "; cat /sys/class/net/${ifaceSanitized}/mtu 2>/dev/null; echo; + echo -n "netdev_group: "; cat /sys/class/net/${ifaceSanitized}/netdev_group 2>/dev/null; echo; + echo -n "operstate: "; cat /sys/class/net/${ifaceSanitized}/operstate 2>/dev/null; echo; + echo -n "proto_down: "; cat /sys/class/net/${ifaceSanitized}/proto_down 2>/dev/null; echo; + echo -n "speed: "; cat /sys/class/net/${ifaceSanitized}/speed 2>/dev/null; echo; + echo -n "tx_queue_len: "; cat /sys/class/net/${ifaceSanitized}/tx_queue_len 2>/dev/null; echo; + echo -n "type: "; cat /sys/class/net/${ifaceSanitized}/type 2>/dev/null; echo; + echo -n "wireless: "; cat /proc/net/wireless 2>/dev/null | grep ${ifaceSanitized}; echo; + echo -n "wirelessspeed: "; iw dev ${ifaceSanitized} link 2>&1 | grep bitrate; echo;`; let lines = []; try { lines = execSync(cmd).toString().split('\n'); - const connectionName = getLinuxIfaceConnectionName(iface); - dhcp = getLinuxIfaceDHCPstatus(iface, connectionName, _dhcpNics); + const connectionName = getLinuxIfaceConnectionName(ifaceSanitized); + dhcp = getLinuxIfaceDHCPstatus(ifaceSanitized, connectionName, _dhcpNics); dnsSuffix = getLinuxIfaceDNSsuffix(connectionName); ieee8021xAuth = getLinuxIfaceIEEE8021xAuth(connectionName); ieee8021xState = getLinuxIfaceIEEE8021xState(ieee8021xAuth); @@ -880,7 +895,7 @@ function networkInterfaces(callback, rescan, defaultString) { carrierChanges = parseInt(util.getValue(lines, 'carrier_changes'), 10); const operstate = util.getValue(lines, 'operstate'); type = operstate === 'up' ? (util.getValue(lines, 'wireless').trim() ? 'wireless' : 'wired') : 'unknown'; - if (iface === 'lo' || iface.startsWith('bond')) { type = 'virtual'; } + if (ifaceSanitized === 'lo' || ifaceSanitized.startsWith('bond')) { type = 'virtual'; } let internal = (ifaces[dev] && ifaces[dev][0]) ? ifaces[dev][0].internal : false; if (dev.toLowerCase().indexOf('loopback') > -1 || ifaceName.toLowerCase().indexOf('loopback') > -1) { @@ -888,7 +903,7 @@ function networkInterfaces(callback, rescan, defaultString) { } const virtual = internal ? false : testVirtualNic(dev, ifaceName, mac); result.push({ - iface, + iface: ifaceSanitized, ifaceName, default: iface === defaultInterface, ip4, @@ -955,6 +970,15 @@ function networkInterfaces(callback, rescan, defaultString) { nics8021xInfo = getWindowsWiredProfilesInformation(); dnsSuffixes = getWindowsDNSsuffixes(); for (let dev in ifaces) { + + let ifaceSanitized = ''; + const s = util.isPrototypePolluted() ? '---' : util.sanitizeShellString(dev); + for (let i = 0; i <= util.mathMin(s.length, 2000); i++) { + if (s[i] !== undefined) { + ifaceSanitized = ifaceSanitized + s[i]; + } + } + let iface = dev; let ip4 = ''; let ip4subnet = ''; @@ -998,7 +1022,7 @@ function networkInterfaces(callback, rescan, defaultString) { - dnsSuffix = getWindowsIfaceDNSsuffix(dnsSuffixes.ifaces, dev); + dnsSuffix = getWindowsIfaceDNSsuffix(dnsSuffixes.ifaces, ifaceSanitized); let foundFirst = false; nics.forEach(detail => { if (detail.mac === mac && !foundFirst) { @@ -1016,7 +1040,7 @@ function networkInterfaces(callback, rescan, defaultString) { type = 'wireless'; } - const IEEE8021x = getWindowsIEEE8021x(type, dev, nics8021xInfo); + const IEEE8021x = getWindowsIEEE8021x(type, ifaceSanitized, nics8021xInfo); ieee8021xAuth = IEEE8021x.protocol; ieee8021xState = IEEE8021x.state; let internal = (ifaces[dev] && ifaces[dev][0]) ? ifaces[dev][0].internal : false;