Skip to content

Commit

Permalink
Fixed a potential "none dereference" if redirect url is absent for HT…
Browse files Browse the repository at this point in the history
…TP redirect codes.
  • Loading branch information
mindstorm38 committed Apr 21, 2024
1 parent 4368a8e commit ae6e9be
Showing 1 changed file with 12 additions and 11 deletions.
23 changes: 12 additions & 11 deletions portablemc/download.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit ae6e9be

Please sign in to comment.