Skip to content

Commit

Permalink
fix(server): handle invalid HTTP requests
Browse files Browse the repository at this point in the history
This commit prevents crashes when receiving invalid HTTP requests.
  • Loading branch information
open-dynaMIX committed Aug 30, 2020
1 parent 971aff1 commit fbe1cab
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions webui.lua
Original file line number Diff line number Diff line change
Expand Up @@ -663,11 +663,18 @@ local function listen(server, passwd)
return
end

local request = parse_request(connection)
if request == nil then
return
local code = 400
local content_type = get_content_type("plain")
local content = "Bad request!"

local success, request = pcall(parse_request, connection)

if success then
if request == nil then
return
end
code, content_type, content = handle_request(request, passwd)
end
local code, content_type, content = handle_request(request, passwd)

connection:send(header(code, content_type, #content))
connection:send(content)
Expand Down

0 comments on commit fbe1cab

Please sign in to comment.