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

Merged
merged 6 commits into from
Jul 3, 2024
Merged
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
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.
ADD-SP marked this conversation as resolved.
Show resolved Hide resolved
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
@@ -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
chobits marked this conversation as resolved.
Show resolved Hide resolved

msg = tostring(msg)

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

3 changes: 2 additions & 1 deletion kong/clustering/rpc/socket.lua
Original file line number Diff line number Diff line change
@@ -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
@@ -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