qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
To: Eric Blake <eblake@redhat.com>, qemu-devel@nongnu.org
Cc: Kevin Wolf <kwolf@redhat.com>,
	"open list:Network Block Dev..." <qemu-block@nongnu.org>,
	Max Reitz <mreitz@redhat.com>
Subject: Re: [PATCH] nbd: Avoid off-by-one in long export name truncation
Date: Tue, 23 Jun 2020 10:20:34 +0300	[thread overview]
Message-ID: <f3182c3b-ff33-f733-a12f-86657713adc7@virtuozzo.com> (raw)
In-Reply-To: <20200622210355.414941-1-eblake@redhat.com>

23.06.2020 00:03, Eric Blake wrote:
> When snprintf returns the same value as the buffer size, the final
> byte was truncated to ensure a NUL terminator.  Fortunately, such long
> export names are unusual enough, with no real impact other than what
> is displayed to the user.
> 
> Fixes: 5c86bdf12089

Oh, I remember myself checking snprintf spec when reviewing this, but
still I missed this thing :(

> Reported-by: Max Reitz <mreitz@redhat.com>
> Signed-off-by: Eric Blake <eblake@redhat.com>

Reviewed-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>

> ---
>   block/nbd.c | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/block/nbd.c b/block/nbd.c
> index eed160c5cda1..8301fcac0589 100644
> --- a/block/nbd.c
> +++ b/block/nbd.c
> @@ -2009,7 +2009,7 @@ static void nbd_refresh_filename(BlockDriverState *bs)
>           len = snprintf(bs->exact_filename, sizeof(bs->exact_filename),
>                          "nbd://%s:%s", host, port);
>       }
> -    if (len > sizeof(bs->exact_filename)) {
> +    if (len >= sizeof(bs->exact_filename)) {
>           /* Name is too long to represent exactly, so leave it empty. */
>           bs->exact_filename[0] = '\0';
>       }
> 

Hmm, interesting, that in case of len=0 (no one branch was executed from previous
if-else-if, which seems possible) we do nothing. Shouldn't this if actually be
if (!len || len >= sizeof(bs->exact_filename)) {
   /* Name is too long or we have nothing to report */
   bs->exact_filename[0] = '\0';
}

Probably not, as bdrv_refresh_filename() does it anyway prior to calling drv->bdrv_refresh_filename().


-- 
Best regards,
Vladimir


      reply	other threads:[~2020-06-23  7:21 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-06-22 21:03 [PATCH] nbd: Avoid off-by-one in long export name truncation Eric Blake
2020-06-23  7:20 ` Vladimir Sementsov-Ogievskiy [this message]

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=f3182c3b-ff33-f733-a12f-86657713adc7@virtuozzo.com \
    --to=vsementsov@virtuozzo.com \
    --cc=eblake@redhat.com \
    --cc=kwolf@redhat.com \
    --cc=mreitz@redhat.com \
    --cc=qemu-block@nongnu.org \
    --cc=qemu-devel@nongnu.org \
    /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
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).