Compare commits

...

3 Commits

Author SHA1 Message Date
Jokob @NetAlertX
69d79dbd7c Merge pull request #1089 from slammingprogramming/main
Some checks are pending
Code checks / check-url-paths (push) Waiting to run
docker / docker_dev (push) Waiting to run
Deploy MkDocs / deploy (push) Waiting to run
Sanitize device fields and prevent crash with numeric hostnames
2025-06-20 15:52:45 +10:00
Ashtin
31806c707f Fixed, Again
Fixes #1088 again. turns out that same thing is used twice. same fix applied
2025-06-20 01:25:04 -04:00
Ashtin
2a4198c2c8 Sanitize device fields and prevent crash with numeric hostnames
This patch improves the resilience of the guess_icon function by sanitizing mac, vendor, and name fields to avoid crashes caused by unexpected data types (e.g., numeric hostnames).

Specifically:

mac is now cast to a string before being uppercased, with a newly added fallback to "00:00:00:00:00:00" if empty or invalid.

vendor is sanitized to a string before lowercasing, still defaulting to "unknown".

name is cast to a string before lowercasing, still falling back to "(unknown)" when empty.

This change not only resolves the error caused by numeric-only hostnames (which triggered an AttributeError due to calling .lower() on an int), but also proactively prevents similar crashes from malformed or unexpected input in the future.

References: Fixes issue #1088 and also let's me sleep a little easier tonight.
2025-06-20 00:46:24 -04:00

View File

@@ -674,9 +674,9 @@ def guess_icon(vendor, mac, ip, name, default):
mylog('debug', [f"[guess_icon] Guessing icon for (vendor|mac|ip|name): ('{vendor}'|'{mac}'|{ip}|{name})"])
result = default
mac = mac.upper()
vendor = vendor.lower() if vendor else "unknown"
name = name.lower() if name else "(unknown)"
mac = str(mac).upper() if mac else "00:00:00:00:00:00"
vendor = str(vendor).lower() if vendor else "unknown"
name = str(name).lower() if name else "(unknown)"
# Guess icon based on vendor
if any(brand in vendor for brand in {"samsung", "motorola"}):
@@ -732,8 +732,8 @@ def guess_icon(vendor, mac, ip, name, default):
# Guess device type
def guess_type(vendor, mac, ip, name, default):
result = default
mac = mac.upper()
vendor = vendor.lower() if vendor else "unknown"
mac = str(mac).upper() if mac else "00:00:00:00:00:00"
vendor = str(vendor).lower() if vendor else "unknown"
name = str(name).lower() if name else "(unknown)"
# Guess icon based on vendor