Tarantool development patches archive
 help / color / mirror / Atom feed
From: Vladimir Davydov <vdavydov.dev@gmail.com>
To: Serge Petrenko <sergepetrenko@tarantool.org>
Cc: kostja@tarantool.org, tarantool-patches@freelists.org
Subject: Re: [tarantool-patches] [PATCH v2] box: fix long uri output in box.info()
Date: Tue, 21 Aug 2018 16:45:42 +0300	[thread overview]
Message-ID: <20180821134542.ad2lsqpbnbsyujnk@esperanza> (raw)
In-Reply-To: <20180821062747.21357-1-sergepetrenko@tarantool.org>

On Tue, Aug 21, 2018 at 09:27:47AM +0300, Serge Petrenko wrote:
> diff --git a/src/uri.c b/src/uri.c
> index 941e7bab9..77a1c88f6 100644
> --- a/src/uri.c
> +++ b/src/uri.c
> @@ -6303,6 +6303,7 @@ int
>  uri_format(char *str, int len, const struct uri *uri, bool write_password)
>  {
>  	int total = 0;
> +	int maxlen = len - 1;
>  	if (uri->scheme_len > 0) {
>  		SNPRINT(total, snprintf, str, len, "%.*s://",
>  			 (int)uri->scheme_len, uri->scheme);
> @@ -6337,7 +6338,7 @@ uri_format(char *str, int len, const struct uri *uri, bool write_password)
>  		SNPRINT(total, snprintf, str, len, "#%.*s",
>  			(int)uri->fragment_len, uri->fragment);
>  	}
> -	return total;
> +	return MIN(total, maxlen);

This is incorrect.

uri_format() should always return the would-be length of the uri string,
even if there's not enough space in the buffer. This is consistent with
snprintf() and this allows the caller to estimate the target buffer size
by calling the function without a buffer:

	int buf_size = uri_format(NULL, 0, uri, false);
	char *buf = malloc(buf_size);

That said, you should fix lbox_pushapplier() instead.

  reply	other threads:[~2018-08-21 13:45 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-08-21  6:27 Serge Petrenko
2018-08-21 13:45 ` Vladimir Davydov [this message]
2018-08-21 14:18   ` Serge Petrenko
2018-08-21 14:58     ` Vladimir Davydov

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=20180821134542.ad2lsqpbnbsyujnk@esperanza \
    --to=vdavydov.dev@gmail.com \
    --cc=kostja@tarantool.org \
    --cc=sergepetrenko@tarantool.org \
    --cc=tarantool-patches@freelists.org \
    --subject='Re: [tarantool-patches] [PATCH v2] box: fix long uri output in box.info()' \
    /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