Skip to content

Commit

Permalink
Fix invalid payload parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
yngvar-antonsson committed Jan 23, 2024
1 parent 265a7f2 commit 9d35f8b
Show file tree
Hide file tree
Showing 7 changed files with 58 additions and 9 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.

## [Unreleased]

### Fixed

- Invalid payload parsing when the message is broken.

## [2.4.2] - 2024-01-18

### Added
Expand Down
12 changes: 11 additions & 1 deletion membership.lua
Original file line number Diff line number Diff line change
Expand Up @@ -779,10 +779,17 @@ local function _member_pack(uri, member)
return nil
end

local payload = member.payload
if payload == msgpack.NULL
or type(payload) ~= 'table'
then
payload = {}
end

return {
uri = uri,
status = opts.STATUS_NAMES[member.status] or tostring(member.status),
payload = member.payload or {},
payload = payload,
incarnation = member.incarnation,
timestamp = member.timestamp,
clock_delta = member.clock_delta,
Expand Down Expand Up @@ -934,6 +941,9 @@ local function set_payload(key, value)
checks('string', '?')
local myself = members.get(advertise_uri)
local payload = myself.payload
if type(payload) ~= 'table' then
payload = {}
end
if payload[key] == value then
return true
end
Expand Down
14 changes: 10 additions & 4 deletions membership/events.lua
Original file line number Diff line number Diff line change
Expand Up @@ -84,11 +84,17 @@ end

function events.unpack(event)
checks('table')
local payload = event[4]
if payload == msgpack.NULL
or type(payload) ~= 'table'
then
payload = nil
end
return {
uri = event[1],
status = event[2],
incarnation = event[3],
payload = (event[4] ~= msgpack.NULL) and event[4] or nil,
uri = tostring(event[1]),
status = tonumber(event[2]),
incarnation = tonumber(event[3]),
payload = payload,
ttl = event[5],
}
end
Expand Down
12 changes: 9 additions & 3 deletions membership/members.lua
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,16 @@ end

function members.unpack(member)
checks('table')
local payload = member[3]
if payload == msgpack.NULL
or type(payload) ~= 'table'
then
payload = nil
end
return member[1], {
status = member[2],
incarnation = member[3],
payload = (member[4] ~= msgpack.NULL) and member[4] or nil,
status = tonumber(member[2]),
incarnation = tonumber(member[3]),
payload = payload,
}
end

Expand Down
9 changes: 9 additions & 0 deletions test/instance.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,15 @@ require('strict').on()
local log = require('log')
local fiber = require('fiber')
local console = require('console')

local checks = require('checks')
package.loaded['checks'] = function(...)
if rawget(_G, "checks_disabled") == true then
return
end
return checks(...)
end

local membership = require('membership')
_G.membership = membership

Expand Down
2 changes: 1 addition & 1 deletion test/test_dissemination.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def test_discover_kill(servers, helpers):
t1 = time.time()

def check_public_opinion():
""" Cheack that all members consider URI has given STATUS """
""" Check that all members consider URI has given STATUS """

for port, srv in list(servers_copy.items()):
member = srv.get_member(uri)
Expand Down
14 changes: 14 additions & 0 deletions test/test_payload.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,17 @@ def test(servers, helpers):
'foo2': 42
}
])

assert servers[13301].conn.eval('''
_G.checks_disabled = true
local opts = require('membership.options')
require('membership.events').generate('13301', opts.ALIVE, 31, 37)
_G.checks_disabled = false
return true
''')[0]
helpers.wait_for(check_payload, [
servers[13302],
'13301',
None,
])

0 comments on commit 9d35f8b

Please sign in to comment.