The Linux Kernel Mailing List
 help / color / mirror / Atom feed
* [PATCH] afs: Replace simple_strtoul with kstrtoul in afs_parse_address
@ 2025-05-27  8:49 Su Hui
  2025-05-29 23:35 ` Jeffrey E Altman
  2025-05-30  9:32 ` David Howells
  0 siblings, 2 replies; 7+ messages in thread
From: Su Hui @ 2025-05-27  8:49 UTC (permalink / raw)
  To: dhowells, marc.dionne; +Cc: Su Hui, linux-afs, linux-kernel, kernel-janitors

kstrtoul() is better because simple_strtoul() ignores overflow which
may lead to unexpected results.

Signed-off-by: Su Hui <suhui@nfschina.com>
---
 fs/afs/addr_prefs.c | 10 ++++------
 1 file changed, 4 insertions(+), 6 deletions(-)

diff --git a/fs/afs/addr_prefs.c b/fs/afs/addr_prefs.c
index c0384201b8fe..ae4f4b371882 100644
--- a/fs/afs/addr_prefs.c
+++ b/fs/afs/addr_prefs.c
@@ -118,7 +118,10 @@ static int afs_parse_address(char *p, struct afs_addr_preference *pref)
 
 	if (*p == '/') {
 		p++;
-		tmp = simple_strtoul(p, &p, 10);
+		if (kstrtoul(p, 10, &tmp)) {
+			pr_warn("Invalid address\n");
+			return -EINVAL;
+		}
 		if (tmp > mask) {
 			pr_warn("Subnet mask too large\n");
 			return -EINVAL;
@@ -130,11 +133,6 @@ static int afs_parse_address(char *p, struct afs_addr_preference *pref)
 		mask = tmp;
 	}
 
-	if (*p) {
-		pr_warn("Invalid address\n");
-		return -EINVAL;
-	}
-
 	pref->subnet_mask = mask;
 	return 0;
 }
-- 
2.30.2


^ permalink raw reply related	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2025-05-30 23:17 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-05-27  8:49 [PATCH] afs: Replace simple_strtoul with kstrtoul in afs_parse_address Su Hui
2025-05-29 23:35 ` Jeffrey E Altman
2025-05-30 10:29   ` Su Hui
2025-05-30 12:43     ` Jeffrey E Altman
2025-05-30 23:17       ` Su Hui
2025-05-30  9:32 ` David Howells
2025-05-30 10:42   ` Su Hui

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox