Skip to content

Commit

Permalink
xrow: fix xrow_decode_synchro rejecting non-int types
Browse files Browse the repository at this point in the history
There was an error in xrow_decode_synchro: it compared the expected type
of the value to the type of the key (MP_UINT) instead of the type of the
actual value. This went unnoticed because all values in synchro requests
were integers.

This is going to change soon, when PROMOTE requests will start holding a
vclock, so fix the wrong type check.

In-scope-of tarantool#9138

NO_DOC=bugfix
NO_CHANGELOG=not user-visible
  • Loading branch information
sergepetrenko committed Nov 14, 2023
1 parent 8410e68 commit 028d7b2
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 2 deletions.
3 changes: 2 additions & 1 deletion src/box/xrow.c
Original file line number Diff line number Diff line change
Expand Up @@ -1294,7 +1294,8 @@ xrow_decode_synchro(const struct xrow_header *row, struct synchro_request *req)
continue;
}
uint8_t key = mp_decode_uint(&d);
if (key < iproto_key_MAX && iproto_key_type[key] != type) {
if (key < iproto_key_MAX &&
iproto_key_type[key] != mp_typeof(*d)) {
xrow_on_decode_err(row, ER_INVALID_MSGPACK,
"request body");
return -1;
Expand Down
28 changes: 27 additions & 1 deletion test/unit/xrow.cc
Original file line number Diff line number Diff line change
Expand Up @@ -543,6 +543,31 @@ test_xrow_decode_unknown_key(void)
footer();
}

static void
test_xrow_decode_synchro_types(void)
{
header();
plan(1);

char buf[128];

const char *p = buf;
const char *end = buf + mp_format(buf, sizeof(buf), "{%u%s}",
IPROTO_INSTANCE_NAME, "somename");
struct xrow_header header;
memset(&header, 0, sizeof(header));
header.bodycnt = 1;
header.body[0].iov_base = buf;
header.body[0].iov_len = mp_format(buf, sizeof(buf), "{%u%s}",
IPROTO_INSTANCE_NAME, "somename");
struct synchro_request synchro;
is(xrow_decode_synchro(&header, &synchro), 0,
"xrow_decode_synchro correctly handles key types");

check_plan();
footer();
}

static void
test_xrow_decode_error_1(void)
{
Expand Down Expand Up @@ -772,7 +797,7 @@ main(void)
memory_init();
fiber_init(fiber_c_invoke);
header();
plan(12);
plan(13);

random_init();

Expand All @@ -789,6 +814,7 @@ main(void)
test_xrow_decode_error_4();
test_xrow_decode_error_gh_9098();
test_xrow_decode_error_gh_9136();
test_xrow_decode_synchro_types();

random_free();
fiber_free();
Expand Down

0 comments on commit 028d7b2

Please sign in to comment.