Skip to contentSkip to conversation

NFS: replace sprintf() with snprintf() in nfs_root_setup

PATCH In review Lalit Shankar Chowdhury 2 participants 2 messages Sep 8 – Sep 9

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 NFS: replace sprintf() with snprintf() in nfs_root_setup

Replace sprintf() with snprintf() to perform bounds checking when formatting.

---
 fs/nfs/nfsroot.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
fs/nfs/nfsroot.c +1 -1
index 432612d22437..d2c26d5378a6 100644
@@ -144,7 +144,7 @@ static int __init nfs_root_setup(char *line)
 		size_t n = strlen(line) + sizeof(NFS_ROOT) - 1;
 		if (n >= sizeof(nfs_root_parms))
 			line[sizeof(nfs_root_parms) - sizeof(NFS_ROOT) - 2] = '\0';
-		sprintf(nfs_root_parms, NFS_ROOT, line);
+		snprintf(nfs_root_parms, sizeof(nfs_root_parms), NFS_ROOT, line);
 	}
 
 	/*
Signature · 1 line
2.53.0
maintainer
#1 lore raw
Quoted 19 lines · Lalit Shankar Chowdhury

Replace sprintf() with snprintf() to perform bounds checking when formatting.

---
 fs/nfs/nfsroot.c | 2 +-

 1 file changed, 1 insertion(+), 1 deletion(-)
fs/nfs/nfsroot.c +0 -0
index 432612d22437..d2c26d5378a6 100644
@@ -144,7 +144,7 @@ static int __init nfs_root_setup(char *line)
  		size_t n = strlen(line) + sizeof(NFS_ROOT) - 1;
  		if (n >= sizeof(nfs_root_parms))

  line[sizeof(nfs_root_parms) - sizeof(NFS_ROOT) - 2] = '\0';

fs/nfs/nfsroot.c +1 -1
-		sprintf(nfs_root_parms, NFS_ROOT, line);
+		snprintf(nfs_root_parms, sizeof(nfs_root_parms),
Quoted 4 lines

NFS_ROOT, line);
  }

  /*

Please see the two lines immediately above the one you're replacing.

Signature · 3 lines
Trond Myklebust
Linux NFS client maintainer, Hammerspace
[email protected], [email protected]