diff mbox series

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

Message ID 20250202204633.1148872-12-jsimmons@infradead.org (mailing list archive)
State New
Headers show
Series lustre: sync to OpenSFS branch May 31, 2023 | expand

Commit Message

James Simmons Feb. 2, 2025, 8:46 p.m. UTC
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 <jsimmons@infradead.org>
Reviewed-on: https://review.whamcloud.com/c/fs/lustre-release/+/49910
Reviewed-by: Andreas Dilger <adilger@whamcloud.com>
Reviewed-by: Arshad Hussain <arshad.hussain@aeoncomputing.com>
Reviewed-by: Oleg Drokin <green@whamcloud.com>
---
 fs/lustre/include/obd.h | 11 +++++------
 1 file changed, 5 insertions(+), 6 deletions(-)
diff mbox series

Patch

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;