From 2a4198c2c8d829581aaac73750a3227e09c05778 Mon Sep 17 00:00:00 2001 From: Ashtin <137578700+slammingprogramming@users.noreply.github.com> Date: Fri, 20 Jun 2025 00:46:24 -0400 Subject: [PATCH] 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. --- server/scan/device_handling.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/server/scan/device_handling.py b/server/scan/device_handling.py index 636b47ce..dff750d0 100755 --- a/server/scan/device_handling.py +++ b/server/scan/device_handling.py @@ -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"}):