Re: [PATCH] ceph: avoid call to strlen() in ceph_mds_auth_match()

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 




On 6/19/24 20:37, Luis Henriques wrote:
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@xxxxxxxxx>
---
  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.

Yeah, you are correct.

Thanks Luis.


Cheers,





[Index of Archives]     [CEPH Users]     [Ceph Large]     [Ceph Dev]     [Information on CEPH]     [Linux BTRFS]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux