Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(clustering/rpc): more strict parameter checking when generating a RPC error #12951

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions changelog/unreleased/kong/fix-rpc-err-msg-checking.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
message: |
More strict parameter checking when generating a RPC error.
type: bugfix
scope: Core
14 changes: 13 additions & 1 deletion kong/clustering/rpc/json_rpc_v2.lua
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,19 @@ local ERROR_MSG = {


function _M.new_error(id, code, msg)
if not msg then
if msg then
if type(msg) ~= "string" then
local mt = getmetatable(msg)
-- other types without the metamethod `__tostring` don't
-- generate a meaningful string, we should consider it as a
-- bug since we should not expose something like
-- `"table: 0x7fff0000"` to the RPC caller.
assert(type(mt.__tostring) == "function")
end

msg = tostring(msg)

else
msg = assert(ERROR_MSG[code], "unknown code: " .. tostring(code))
end

Expand Down
3 changes: 2 additions & 1 deletion kong/clustering/rpc/socket.lua
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ local constants = require("kong.constants")


local assert = assert
local unpack = unpack
local string_format = string.format
local kong = kong
local is_timeout = utils.is_timeout
Expand Down Expand Up @@ -68,7 +69,7 @@ function _M._dispatch(premature, self, cb, payload)
ngx_log(ngx_WARN, "[rpc] RPC callback failed: ", err)

res, err = self.outgoing:push(new_error(payload.id, jsonrpc.SERVER_ERROR,
tostring(err)))
err))
if not res then
ngx_log(ngx_WARN, "[rpc] unable to push RPC call error: ", err)
end
Expand Down