mirror of
https://github.com/jokob-sk/NetAlertX.git
synced 2025-12-07 09:36:05 -08:00
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.
This commit is contained in:
@@ -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})"])
|
mylog('debug', [f"[guess_icon] Guessing icon for (vendor|mac|ip|name): ('{vendor}'|'{mac}'|{ip}|{name})"])
|
||||||
|
|
||||||
result = default
|
result = default
|
||||||
mac = mac.upper()
|
mac = str(mac).upper() if mac else "00:00:00:00:00:00"
|
||||||
vendor = vendor.lower() if vendor else "unknown"
|
vendor = str(vendor).lower() if vendor else "unknown"
|
||||||
name = name.lower() if name else "(unknown)"
|
name = str(name).lower() if name else "(unknown)"
|
||||||
|
|
||||||
# Guess icon based on vendor
|
# Guess icon based on vendor
|
||||||
if any(brand in vendor for brand in {"samsung", "motorola"}):
|
if any(brand in vendor for brand in {"samsung", "motorola"}):
|
||||||
|
|||||||
Reference in New Issue
Block a user