Skip to contentSkip to conversation

fs: fat: inode: Replace sprintf() with scnprintf()

PATCH Applied Maxwell Doose 2 participants 2 messages Jun 3 – Jun 4

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

PATCH 1/1 fs: fat: inode: Replace sprintf() with scnprintf()

The kernel documentation notes that sprintf() is deprecated and unsafe. Replace it with the more preferred scnprintf() to help with hardening.

---
Test compiled only, as the only functional change is the addition of bounds checking.

 fs/fat/inode.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
fs/fat/inode.c +1 -1
index 28f78df086ef..b032bbc6855c 100644
@@ -1786,7 +1786,7 @@ int fat_fill_super(struct super_block *sb, struct fs_context *fc,
 	 */
 
 	error = -EINVAL;
-	sprintf(buf, "cp%d", sbi->options.codepage);
+	scnprintf(buf, sizeof(buf), "cp%d", sbi->options.codepage);
 	sbi->nls_disk = load_nls(buf);
 	if (!sbi->nls_disk) {
 		fat_msg(sb, KERN_ERR, "codepage %s not found", buf);
Signature · 1 line
2.54.0
maintainer Acked-by on v1 1/1
#1 lore raw
Quoted 4 lines · Maxwell Doose

The kernel documentation notes that sprintf() is deprecated and unsafe. Replace it with the more preferred scnprintf() to help with hardening.

Quoted 20 lines

---
Test compiled only, as the only functional change is the addition of bounds checking.

 fs/fat/inode.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
fs/fat/inode.c +1 -1
index 28f78df086ef..b032bbc6855c 100644
@@ -1786,7 +1786,7 @@ int fat_fill_super(struct super_block *sb, struct fs_context *fc,
 	 */
 
 	error = -EINVAL;
-	sprintf(buf, "cp%d", sbi->options.codepage);
+	scnprintf(buf, sizeof(buf), "cp%d", sbi->options.codepage);
 	sbi->nls_disk = load_nls(buf);
 	if (!sbi->nls_disk) {
 		fat_msg(sb, KERN_ERR, "codepage %s not found", buf);
Signature · 1 line
OGAWA Hirofumi <[email protected]>