[lustre-devel] [PATCH 11/33] lustre: obd: replace simple_strtoul()

James Simmons <[email protected]> Sun, 2 Feb 2025 15:46:11 -0500
Newsgroups org.lustre.lists.lustre-devel
Message-ID <[email protected]>
Replace the use of simple_strtoul() in filename_is_volatile() with
sscanf(). This change also strengthens the checking of the format
of the volatile file's name.

WC-bug-id: https://jira.whamcloud.com/browse/LU-9325
Lustre-commit: 79b34a83f811f5f1d ("LU-9325 obd: replace simple_strtoul()")
Signed-off-by: James Simmons <[email protected]>
Reviewed-on: https://review.whamcloud.com/c/fs/lustre-release/+/49910
Reviewed-by: Andreas Dilger <[email protected]>
Reviewed-by: Arshad Hussain <[email protected]>
Reviewed-by: Oleg Drokin <[email protected]>
---
 fs/lustre/include/obd.h | 11 +++++------
 1 file changed, 5 insertions(+), 6 deletions(-)

diff --git a/fs/lustre/include/obd.h b/fs/lustre/include/obd.h
index 174372001b23..c62d9171150a 100644
--- a/fs/lustre/include/obd.h
+++ b/fs/lustre/include/obd.h
@@ -1219,7 +1219,7 @@ static inline bool filename_is_volatile(const char *name, size_t namelen,
 					int *idx)
 {
 	const char *start;
-	char *end;
+	int rnd, fd, rc;
 
 	if (strncmp(name, LUSTRE_VOLATILE_HDR, LUSTRE_VOLATILE_HDR_LEN) != 0)
 		return false;
@@ -1241,12 +1241,11 @@ static inline bool filename_is_volatile(const char *name, size_t namelen,
 	}
 	/* we have an idx, read it */
 	start = name + LUSTRE_VOLATILE_HDR_LEN + 1;
-	*idx = simple_strtoul(start, &end, 0);
-	/* error cases:
-	 * no digit, no trailing :, negative value
+	rc = sscanf(start, "%4x:%4x:fd=%2d", idx, &rnd, &fd);
+	/* error cases: no digit or negative value
+	 * rc will never be larger then 3
 	 */
-	if (((*idx == 0) && (end == start)) ||
-	    (*end != ':') || (*idx < 0))
+	if (rc <= 0 || *idx < 0)
 		goto bad_format;
 
 	return true;
-- 
2.39.3

_______________________________________________
lustre-devel mailing list
[email protected]
http://lists.lustre.org/listinfo.cgi/lustre-devel-lustre.org