luci-base: fix handling of large ubus HTTP requests

Properly handle ubus POST requests exceeding the default chunk size
and fix a possible nil dereference when rejecting incoming requests
due to bad JSON message framing.

Signed-off-by: Jo-Philipp Wich <jo@mein.io>
This commit is contained in:
Jo-Philipp Wich 2019-06-06 19:19:31 +02:00
parent 79be2d57cd
commit c5b6f42943

View file

@ -161,7 +161,7 @@ local ubus_types = {
local function ubus_request(req)
if type(req) ~= "table" or type(req.method) ~= "string" or type(req.params) ~= "table" or
#req.params < 2 or req.jsonrpc ~= "2.0" or req.id == nil then
return ubus_reply(req.id, nil, -32600, "Invalid request")
return ubus_reply(nil, nil, -32600, "Invalid request")
elseif req.method == "call" then
local sid, obj, fun, arg =
@ -216,7 +216,16 @@ end
function action_ubus()
local parser = require "luci.jsonc".new()
luci.http.context.request:setfilehandler(function(_, s) parser:parse(s or "") end)
luci.http.context.request:setfilehandler(function(_, s)
if not s then
return nil
end
local ok, err = parser:parse(s)
return (not err or nil)
end)
luci.http.context.request:content()
local json = parser:get()