diff options
author | Jo-Philipp Wich <jo@mein.io> | 2019-06-06 19:19:31 +0200 |
---|---|---|
committer | Jo-Philipp Wich <jo@mein.io> | 2019-07-07 15:36:25 +0200 |
commit | c5b6f4294325652899ccca0419d7058cfadd7c85 (patch) | |
tree | 81db82edbd14ea7bf70d7028aa5b8ac2d34d268e /modules/luci-base/luasrc/controller | |
parent | 79be2d57cde7a360a1004ebf5980caf2bd969212 (diff) |
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>
Diffstat (limited to 'modules/luci-base/luasrc/controller')
-rw-r--r-- | modules/luci-base/luasrc/controller/admin/index.lua | 13 |
1 files changed, 11 insertions, 2 deletions
diff --git a/modules/luci-base/luasrc/controller/admin/index.lua b/modules/luci-base/luasrc/controller/admin/index.lua index 259c34eee8..9fcfe4a309 100644 --- a/modules/luci-base/luasrc/controller/admin/index.lua +++ b/modules/luci-base/luasrc/controller/admin/index.lua @@ -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() |