All of lore.kernel.org
 help / color / mirror / Atom feed
From: Luis Henriques <luis.henriques@linux.dev>
To: Dmitry Antipov <dmantipov@yandex.ru>
Cc: Xiubo Li <xiubli@redhat.com>,  ceph-devel@vger.kernel.org
Subject: Re: [PATCH] ceph: avoid call to strlen() in ceph_mds_auth_match()
Date: Wed, 19 Jun 2024 13:37:34 +0100	[thread overview]
Message-ID: <87bk3xglbl.fsf@brahms.olymp> (raw)
In-Reply-To: <20240618143640.169194-1-dmantipov@yandex.ru> (Dmitry Antipov's message of "Tue, 18 Jun 2024 17:36:40 +0300")

On Tue 18 Jun 2024 05:36:40 PM +03, Dmitry Antipov wrote;

> Since 'snprintf()' returns the number of characters emitted,
> an extra call to 'strlen()' in 'ceph_mds_auth_match()' may
> be dropped. Compile tested only.
>
> Signed-off-by: Dmitry Antipov <dmantipov@yandex.ru>
> ---
>  fs/ceph/mds_client.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/fs/ceph/mds_client.c b/fs/ceph/mds_client.c
> index c2157f6e0c69..7224283046a7 100644
> --- a/fs/ceph/mds_client.c
> +++ b/fs/ceph/mds_client.c
> @@ -5665,9 +5665,9 @@ static int ceph_mds_auth_match(struct ceph_mds_client *mdsc,
>  				if (!_tpath)
>  					return -ENOMEM;
>  				/* remove the leading '/' */
> -				snprintf(_tpath, n, "%s/%s", spath + 1, tpath);
> +				tlen = snprintf(_tpath, n, "%s/%s",
> +						spath + 1, tpath);
>  				free_tpath = true;
> -				tlen = strlen(_tpath);
>  			}

Unless I'm missing something, this patch is incorrect.  snprintf() may not
return the actual string length *if* the output is truncated.  For
example:

	snprintf(str, 5, "%s", "0123456789");

snprintf() will return 10, while strlen(str) will return 4.

Cheers,
-- 
Luís

  parent reply	other threads:[~2024-06-19 12:37 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-06-18 14:36 [PATCH] ceph: avoid call to strlen() in ceph_mds_auth_match() Dmitry Antipov
2024-06-19  0:13 ` Xiubo Li
2024-06-19 12:37 ` Luis Henriques [this message]
2024-06-19 13:07   ` Xiubo Li

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=87bk3xglbl.fsf@brahms.olymp \
    --to=luis.henriques@linux.dev \
    --cc=ceph-devel@vger.kernel.org \
    --cc=dmantipov@yandex.ru \
    --cc=xiubli@redhat.com \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.