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 75f2f01
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 5 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
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
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
16 changes: 16 additions & 0 deletions test/test_payload.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,19 @@ def test(servers, helpers):
'foo2': 42
}
])

assert servers[13301].conn.eval('''
local old_checks = package.loaded['checks']
package.loaded['checks'] = function() end
require('membership.events').generate(13301, 29, 31, 37)
package.loaded['checks'] = old_checks
return true
''')[0]
helpers.wait_for(check_payload, [
servers[13302],
'13301',
None,
])

0 comments on commit 75f2f01

Please sign in to comment.