diff options
author | Adam Harrison <adamdharrison@gmail.com> | 2022-11-30 00:11:59 -0500 |
---|---|---|
committer | Adam Harrison <adamdharrison@gmail.com> | 2022-11-30 00:11:59 -0500 |
commit | 979bf050a2ee8abdbf8c6b3556ac4fc051be8de9 (patch) | |
tree | 3fe6ff7709a48a01375c69cca557abfcf838ccb6 | |
parent | 5788acb842cb828471120fd512c0c43a90048a6b (diff) | |
download | lite-xl-plugin-manager-979bf050a2ee8abdbf8c6b3556ac4fc051be8de9.tar.gz lite-xl-plugin-manager-979bf050a2ee8abdbf8c6b3556ac4fc051be8de9.zip |
Added in redirect guard.
-rw-r--r-- | src/lpm.lua | 7 |
1 files changed, 4 insertions, 3 deletions
diff --git a/src/lpm.lua b/src/lpm.lua index 034bfdc..c8198d8 100644 --- a/src/lpm.lua +++ b/src/lpm.lua @@ -459,21 +459,22 @@ local function prompt(message) end -function common.get(source, target, checksum) +function common.get(source, target, checksum, depth) if not source then error("requires url") end + if depth > 10 then error("too many redirects") end local _, _, protocol, hostname, port, rest = source:find("^(https?)://([^:/?]+):?(%d*)(.*)$") if not protocol then error("malfomed url " .. source) end if not port or port == "" then port = protocol == "https" and 443 or 80 end if not checksum then local res, headers = system.get(protocol, hostname, port, rest, target) - if headers.location then return common.get(headers.location, target, checksum) end + if headers.location then return common.get(headers.location, target, checksum, (depth or 0) + 1) end return res end if not system.stat(CACHEDIR .. PATHSEP .. "files") then common.mkdirp(CACHEDIR .. PATHSEP .. "files") end local cache_path = CACHEDIR .. PATHSEP .. "files" .. PATHSEP .. checksum if not system.stat(cache_path) then local res, headers = system.get(source, cache_path) - if headers.location then return common.get(headers.location, target, checksum) end + if headers.location then return common.get(headers.location, target, checksum, (depth or 0) + 1) end if checksum ~= "SKIP" and system.hash(cache_path, "file") ~= checksum then fatal_warning("checksum doesn't match for " .. source) end end common.copy(cache_path, target) |