[lustre-devel] [PATCH 11/33] lustre: obd: replace simple_strtoul()
James Simmons
jsimmons at infradead.org
Sun Feb 2 12:46:11 PST 2025
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 at infradead.org>
Reviewed-on: https://review.whamcloud.com/c/fs/lustre-release/+/49910
Reviewed-by: Andreas Dilger <adilger at whamcloud.com>
Reviewed-by: Arshad Hussain <arshad.hussain at aeoncomputing.com>
Reviewed-by: Oleg Drokin <green at whamcloud.com>
---
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
More information about the lustre-devel
mailing list