From d1a60af560d47e45773aee970c4f4c75e29326e1 Mon Sep 17 00:00:00 2001 From: Alexey Vishnyakov <vishnya@ispras.ru> Date: Tue, 30 Nov 2021 18:51:29 +0300 Subject: [PATCH] swim: fix debug assertion abort in proto decode assert(cur < end) after mp_load_u8 in mp_check_binl was failing --- src/lib/swim/swim_proto.c | 2 +- test/unit/swim_proto.c | 10 ++++++++-- test/unit/swim_proto.result | 3 ++- 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/src/lib/swim/swim_proto.c b/src/lib/swim/swim_proto.c index a3b913b339..b7eb94c8f7 100644 --- a/src/lib/swim/swim_proto.c +++ b/src/lib/swim/swim_proto.c @@ -125,7 +125,7 @@ static inline int swim_decode_bin(const char **bin, uint32_t *size, const char **pos, const char *end, const char *prefix, const char *param_name) { - if (*pos == end || mp_typeof(**pos) != MP_BIN || + if (*pos + 1 >= end || mp_typeof(**pos) != MP_BIN || mp_check_binl(*pos, end) > 0) { diag_set(SwimError, "%s %s should be bin", prefix, param_name); diff --git a/test/unit/swim_proto.c b/test/unit/swim_proto.c index 6aab07d5a2..6bdcde4224 100644 --- a/test/unit/swim_proto.c +++ b/test/unit/swim_proto.c @@ -45,7 +45,7 @@ static void swim_test_member_def(void) { header(); - plan(12); + plan(13); struct swim_member_def mdef; const char *pos = buffer; @@ -129,6 +129,12 @@ swim_test_member_def(void) is(swim_member_def_decode(&mdef, &pos, end, "test"), 0, "normal member def"); + pos = buffer; + end = mp_encode_bin(buffer, (const char *) &uuid, sizeof(uuid)); + end = buffer + 1; + is(swim_decode_uuid(&uuid, &pos, end, "test", "test"), -1, + "zero length bin"); + check_plan(); footer(); } @@ -264,4 +270,4 @@ main() int rc = check_plan(); footer(); return rc; -} \ No newline at end of file +} diff --git a/test/unit/swim_proto.result b/test/unit/swim_proto.result index 8a41a5d405..bb2b5c8539 100644 --- a/test/unit/swim_proto.result +++ b/test/unit/swim_proto.result @@ -1,7 +1,7 @@ *** main *** 1..3 *** swim_test_member_def *** - 1..12 + 1..13 ok 1 - not map header ok 2 - not uint member key ok 3 - too big member key @@ -14,6 +14,7 @@ ok 10 - uuid is nil/undefined ok 11 - port is 0/undefined ok 12 - normal member def + ok 13 - zero length bin ok 1 - subtests *** swim_test_member_def: done *** *** swim_test_meta *** -- GitLab