From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-lf1-f47.google.com (mail-lf1-f47.google.com [209.85.167.47]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by dev.tarantool.org (Postfix) with ESMTPS id EB3A24765E0 for ; Tue, 22 Dec 2020 14:15:01 +0300 (MSK) Received: by mail-lf1-f47.google.com with SMTP id h22so21543264lfu.2 for ; Tue, 22 Dec 2020 03:15:01 -0800 (PST) From: Cyrill Gorcunov Date: Tue, 22 Dec 2020 14:14:07 +0300 Message-Id: <20201222111408.48368-5-gorcunov@gmail.com> In-Reply-To: <20201222111408.48368-1-gorcunov@gmail.com> References: <20201222111408.48368-1-gorcunov@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: [Tarantool-patches] [PATCH v6 4/5] cfg: more precise check for replication_synchro_quorum value List-Id: Tarantool development patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: tml Cc: Vladislav Shpilevoy 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 Signed-off-by: Cyrill Gorcunov --- 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