From ae6e9be0cf06cee906892bff98552791b5d1d8a2 Mon Sep 17 00:00:00 2001 From: Theo Rozier Date: Sat, 20 Apr 2024 12:41:37 +0200 Subject: [PATCH] Fixed a potential "none dereference" if redirect url is absent for HTTP redirect codes. --- portablemc/download.py | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/portablemc/download.py b/portablemc/download.py index 4d00e4f4..e6fdd842 100644 --- a/portablemc/download.py +++ b/portablemc/download.py @@ -330,17 +330,18 @@ def _download_thread( pass if res.status == 301 or res.status == 302: - - redirect_url = res.headers["location"] - redirect_entry = DownloadEntry( - redirect_url, - entry.dst, - size=entry.size, - sha1=entry.sha1, - name=entry.name) - - entries_queue.put(_DownloadEntry.from_entry(redirect_entry)) - break # Abort on redirect + # If location header is absent, consider it not found. + redirect_url = res.headers.get("location") + if redirect_url is not None: + redirect_entry = DownloadEntry( + redirect_url, + entry.dst, + size=entry.size, + sha1=entry.sha1, + name=entry.name) + + entries_queue.put(_DownloadEntry.from_entry(redirect_entry)) + break # Abort on redirect # Any other non-200 code is considered not found and we retry... last_error = DownloadResultError.NOT_FOUND