Tarantool development patches archive
 help / color / mirror / Atom feed
From: Serge Petrenko <sergepetrenko@tarantool.org>
To: Cyrill Gorcunov <gorcunov@gmail.com>,
	tml <tarantool-patches@dev.tarantool.org>
Cc: Vladislav Shpilevoy <v.shpilevoy@tarantool.org>
Subject: Re: [Tarantool-patches] [PATCH v2 1/2] raft: raft_request_to_string -- don't hardcode size
Date: Fri, 30 Oct 2020 10:21:16 +0300	[thread overview]
Message-ID: <27575b28-dbc1-1443-1527-c771c62bc699@tarantool.org> (raw)
In-Reply-To: <20201029083707.309206-2-gorcunov@gmail.com>


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 <gorcunov@gmail.com>
> ---
>   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

  reply	other threads:[~2020-10-30  7:21 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-10-29  8:37 [Tarantool-patches] [PATCH v2 0/2] raft: a few fixes for raft state symbolics Cyrill Gorcunov
2020-10-29  8:37 ` [Tarantool-patches] [PATCH v2 1/2] raft: raft_request_to_string -- don't hardcode size Cyrill Gorcunov
2020-10-30  7:21   ` Serge Petrenko [this message]
2020-10-29  8:37 ` [Tarantool-patches] [PATCH v2 2/2] raft: decode even invalid states of raft Cyrill Gorcunov
2020-10-29  9:37 ` [Tarantool-patches] [PATCH v2 0/2] raft: a few fixes for raft state symbolics Cyrill Gorcunov
2020-11-02 22:02 ` Vladislav Shpilevoy

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=27575b28-dbc1-1443-1527-c771c62bc699@tarantool.org \
    --to=sergepetrenko@tarantool.org \
    --cc=gorcunov@gmail.com \
    --cc=tarantool-patches@dev.tarantool.org \
    --cc=v.shpilevoy@tarantool.org \
    --subject='Re: [Tarantool-patches] [PATCH v2 1/2] raft: raft_request_to_string -- don'\''t hardcode size' \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox