[Tarantool-patches] [PATCH v4] lua/key_def: fix compare_with_key() part count check

Alexander Turenko alexander.turenko at tarantool.org
Thu Dec 24 01:49:49 MSK 2020


> Issue: https://github.com/tarantool/tarantool/issues/5307
> Branch: https://github.com/tarantool/tarantool/tree/void234/gh-5307-fix-key_def-part-count-check-v4

LGTM.

I left several style / taste comments regarding the test. It is just for
you. I think they don't worth one more review iteration.

Alexander Ti., please, approve the push from the QA team side.

Kirill, please, push to master and cherry-pick to 2.6 and 2.5.

Changelog entry ('Lua' section):

* Fixed a segfault in `key_def.compare_with_key()` on an invalid key (gh-5307).

WBR, Alexander Turenko.

----

> diff --git a/test/box-tap/gh-5307-key_def-part-count-check.test.lua b/test/box-tap/gh-5307-key_def-part-count-check.test.lua
> new file mode 100755
> index 000000000..d9458c95a
> --- /dev/null
> +++ b/test/box-tap/gh-5307-key_def-part-count-check.test.lua
> @@ -0,0 +1,26 @@
> +#!/usr/bin/env tarantool
> +
> +local tap = require('tap')
> +local mytest = tap.test('key_def part count tests')
> +
> +mytest:plan(3)

Usually 'test'.

> +
> +local key_def = require('key_def')

Usually all requires are go first, when possible.

> +local kd = key_def.new({{fieldno = 1, type = 'unsigned'}})
> +local ok, res
> +
> +-- Should succeed

We trying to write comments in the same style: start with a capital
letter, end with a period.

> +ok, res = pcall(kd.compare_with_key, kd, {1}, {1})
> +mytest:ok(ok and res == 0, "Simple equality")

In my personal taste, it is good to use the same quotes (single or
double) when possible within at least a file. (I prefer single ones, but
without any reason, just get into the habit.)

> +
> +-- Should succeed
> +ok, res = pcall(kd.compare_with_key, kd, {1}, {2})
> +mytest:ok(ok and res < 0, "Simple inequality")
> +
> +-- Should fail
> +local exp_err = "Invalid key part count (expected [0..1], got 9)"
> +ok, res = pcall(kd.compare_with_key, kd, {1}, {1, 2, 3, 4, 5, 6, 7, 8, 9})
> +mytest:is_deeply({ok, tostring(res)}, {false, exp_err},
> +    "Invalid key part count")
> +
> +os.exit(mytest:check() and 0 or 1)
> -- 
> 2.25.1
> 


More information about the Tarantool-patches mailing list