From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Date: Tue, 21 Aug 2018 16:45:42 +0300 From: Vladimir Davydov Subject: Re: [tarantool-patches] [PATCH v2] box: fix long uri output in box.info() Message-ID: <20180821134542.ad2lsqpbnbsyujnk@esperanza> References: <20180821062747.21357-1-sergepetrenko@tarantool.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20180821062747.21357-1-sergepetrenko@tarantool.org> To: Serge Petrenko Cc: kostja@tarantool.org, tarantool-patches@freelists.org List-ID: 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.