[Tarantool-patches] [PATCH v6 4/5] cfg: more precise check for replication_synchro_quorum value

Cyrill Gorcunov gorcunov at gmail.com
Tue Dec 22 14:14:07 MSK 2020


When we fetch replication_synchro_quorum value (either as
a plain integer or via formula evaluation) we trim the
number down to integer, which silently hides potential
overflow errors.

For example

 | box.cfg{replication_synchro_quorum='4294967297'}

which is 1 in terms of machine words. Lets use 8 bytes
values and trigger an error instead.

Part-of #5446

Reported-by: Vladislav Shpilevoy <v.shpilevoy at tarantool.org>
Signed-off-by: Cyrill Gorcunov <gorcunov at gmail.com>
---
 src/box/box.cc | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/src/box/box.cc b/src/box/box.cc
index 68579c254..b3cc45358 100644
--- a/src/box/box.cc
+++ b/src/box/box.cc
@@ -609,9 +609,9 @@ box_eval_replication_synchro_quorum(int nr_replicas)
 		return -1;
 	}
 
-	int quorum = -1;
+	int64_t quorum = -1;
 	if (lua_isnumber(tarantool_L, -1))
-		quorum = (int)lua_tonumber(tarantool_L, -1);
+		quorum = luaL_toint64(tarantool_L, -1);
 	lua_pop(tarantool_L, 1);
 
 	/*
@@ -657,7 +657,7 @@ box_check_replication_synchro_quorum(void)
 		return 0;
 	}
 
-	int quorum = cfg_geti("replication_synchro_quorum");
+	int64_t quorum = cfg_geti64("replication_synchro_quorum");
 	if (quorum <= 0 || quorum >= VCLOCK_MAX) {
 		diag_set(ClientError, ER_CFG, "replication_synchro_quorum",
 			 "the value must be greater than zero and less than "
-- 
2.26.2



More information about the Tarantool-patches mailing list