[PATCH] fs: fat: inode: Replace sprintf() with scnprintf()

Maxwell Doose posted 1 patch 4 days, 16 hours ago
fs/fat/inode.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
[PATCH] fs: fat: inode: Replace sprintf() with scnprintf()
Posted by Maxwell Doose 4 days, 16 hours ago
The kernel documentation notes that sprintf() is deprecated and unsafe.
Replace it with the more preferred scnprintf() to help with hardening.

Signed-off-by: Maxwell Doose <m32285159@gmail.com>
---
 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(-)

diff --git a/fs/fat/inode.c b/fs/fat/inode.c
index 28f78df086ef..b032bbc6855c 100644
--- a/fs/fat/inode.c
+++ b/fs/fat/inode.c
@@ -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);
-- 
2.54.0
Re: [PATCH] fs: fat: inode: Replace sprintf() with scnprintf()
Posted by OGAWA Hirofumi 4 days, 1 hour ago
Maxwell Doose <m32285159@gmail.com> writes:

> The kernel documentation notes that sprintf() is deprecated and unsafe.
> Replace it with the more preferred scnprintf() to help with hardening.
>
> Signed-off-by: Maxwell Doose <m32285159@gmail.com>

Acked-by: OGAWA Hirofumi <hirofumi@mail.parknet.co.jp>

> ---
>  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(-)
>
> diff --git a/fs/fat/inode.c b/fs/fat/inode.c
> index 28f78df086ef..b032bbc6855c 100644
> --- a/fs/fat/inode.c
> +++ b/fs/fat/inode.c
> @@ -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);

-- 
OGAWA Hirofumi <hirofumi@mail.parknet.co.jp>