From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from smtp52.i.mail.ru (smtp52.i.mail.ru [94.100.177.112]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dev.tarantool.org (Postfix) with ESMTPS id 39C87469719 for ; Fri, 30 Oct 2020 10:21:17 +0300 (MSK) References: <20201029083707.309206-1-gorcunov@gmail.com> <20201029083707.309206-2-gorcunov@gmail.com> From: Serge Petrenko Message-ID: <27575b28-dbc1-1443-1527-c771c62bc699@tarantool.org> Date: Fri, 30 Oct 2020 10:21:16 +0300 MIME-Version: 1.0 In-Reply-To: <20201029083707.309206-2-gorcunov@gmail.com> Content-Type: text/plain; charset="utf-8"; format="flowed" Content-Transfer-Encoding: 8bit Content-Language: en-GB Subject: Re: [Tarantool-patches] [PATCH v2 1/2] raft: raft_request_to_string -- don't hardcode size List-Id: Tarantool development patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Cyrill Gorcunov , tml Cc: Vladislav Shpilevoy 29.10.2020 11:37, Cyrill Gorcunov пишет: > The size should be matched to the real size of a buffer, > otherwise it is a room for mistake. Same time make sure > we're not overriding the buffer. Hi! Thanks for the patch! LGTM. > > Signed-off-by: Cyrill Gorcunov > --- > src/box/raft.c | 12 ++++++------ > 1 file changed, 6 insertions(+), 6 deletions(-) > > diff --git a/src/box/raft.c b/src/box/raft.c > index 4a8e54cac..7c546de8c 100644 > --- a/src/box/raft.c > +++ b/src/box/raft.c > @@ -275,36 +275,36 @@ static const char * > raft_request_to_string(const struct raft_request *req) > { > assert(req->term != 0); > - int size = 1024; > char buf[1024]; > + int size = sizeof(buf); > char *pos = buf; > int rc = snprintf(pos, size, "{term: %llu", > (unsigned long long)req->term); > - assert(rc >= 0); > + assert(rc >= 0 && rc < size); > pos += rc; > size -= rc; > if (req->vote != 0) { > rc = snprintf(pos, size, ", vote: %u", req->vote); > - assert(rc >= 0); > + assert(rc >= 0 && rc < size); > pos += rc; > size -= rc; > } > if (req->state != 0) { > rc = snprintf(pos, size, ", state: %s", > raft_state_strs[req->state]); > - assert(rc >= 0); > + assert(rc >= 0 && rc < size); > pos += rc; > size -= rc; > } > if (req->vclock != NULL) { > rc = snprintf(pos, size, ", vclock: %s", > vclock_to_string(req->vclock)); > - assert(rc >= 0); > + assert(rc >= 0 && rc < size); > pos += rc; > size -= rc; > } > rc = snprintf(pos, size, "}"); > - assert(rc >= 0); > + assert(rc >= 0 && rc < size); > pos += rc; > return tt_cstr(buf, pos - buf); > } -- Serge Petrenko