From 75f2f01f59478e39c24d05fc2449b74d80fa1c5d Mon Sep 17 00:00:00 2001 From: Igor Zolotarev Date: Tue, 23 Jan 2024 19:15:56 +0300 Subject: [PATCH] Fix invalid payload parsing --- CHANGELOG.md | 4 ++++ membership/events.lua | 14 ++++++++++---- test/test_dissemination.py | 2 +- test/test_payload.py | 16 ++++++++++++++++ 4 files changed, 31 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 37a88e9..bf91b90 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/membership/events.lua b/membership/events.lua index 95cca95..1bd884b 100644 --- a/membership/events.lua +++ b/membership/events.lua @@ -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 diff --git a/test/test_dissemination.py b/test/test_dissemination.py index 458ffdf..3a4d4b3 100644 --- a/test/test_dissemination.py +++ b/test/test_dissemination.py @@ -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) diff --git a/test/test_payload.py b/test/test_payload.py index 2e38f18..5cf9513 100644 --- a/test/test_payload.py +++ b/test/test_payload.py @@ -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, + ])