fix: harden endpoints against malformed input (final-review findings)

- /api/repeaters: bad ?limit= falls back to 25 instead of crashing the handler
- repeaters.load(): tolerate a corrupted repeaters.json (JSONDecodeError -> [])
- tune_repeater/do_POST: catch TypeError so a null field yields {ok:false} not a reset
This commit is contained in:
2026-06-14 16:29:10 -04:00
parent e28dae2ba4
commit 5d48ad0bfe
3 changed files with 7 additions and 4 deletions
+5 -2
View File
@@ -90,7 +90,10 @@ class Handler(BaseHTTPRequestHandler):
from urllib.parse import urlparse, parse_qs
qs = parse_qs(urlparse(self.path).query)
q = qs.get("q", [""])[0]
limit = int(qs.get("limit", ["25"])[0])
try:
limit = int(qs.get("limit", ["25"])[0])
except ValueError:
limit = 25
recs = repeaters.search(repeaters.load(REPEATERS_JSON), q, limit)
self._json({"ok": True, "repeaters": recs})
else:
@@ -101,7 +104,7 @@ class Handler(BaseHTTPRequestHandler):
try:
body = json.loads(self.rfile.read(length) or b"{}")
self._json(apply_control(self.path, body))
except (CIVError, OSError, ValueError, KeyError) as e:
except (CIVError, OSError, ValueError, TypeError, KeyError) as e:
self._json({"ok": False, "error": str(e)}, 200)