[tarantool-patches] [PATCH v2] box: fix long uri output in box.info()

Vladimir Davydov vdavydov.dev at gmail.com
Tue Aug 21 16:45:42 MSK 2018


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.



More information about the Tarantool-patches mailing list