f2fs: replace deprecated strcpy with strscpy
PATCH v2 1/1 f2fs: replace deprecated strcpy with strscpy
strcpy is deprecated. Kernel docs recommend replacing strcpy with strscpy. The function strcpy() return value isn't used so there shouldn't be an issue replacing with the safer alternative strscpy.
---
V1 -> V2: handle strscpy errors, changed prefix to f2fs
fs/f2fs/super.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-)
fs/f2fs/super.c +8 -2
@@ -5,6 +5,7 @@* Copyright (c) 2012 Samsung Electronics Co., Ltd. * http://www.samsung.com/ */ #include <linux/module.h> #include <linux/init.h> #include <linux/fs.h>
@@ -1158,7 +1159,10 @@ static int parse_options(struct super_block *sb, char *options, bool is_remount)break ; } -strcpy (ext[ext_cnt], name); +if (strscpy (ext[ext_cnt], name) == -E2BIG ) { +kfree (name); +return -EINVAL ; + }F2FS_OPTION (sbi).compress_ext_cnt++;kfree (name);break ;
@@ -1187,7 +1191,10 @@ static int parse_options(struct super_block *sb, char *options, bool is_remount)break ; } -strcpy (noext[noext_cnt], name); +if (strscpy (noext[noext_cnt], name) == -E2BIG ) { +kfree (name); +return -EINVAL ; + }F2FS_OPTION (sbi).nocompress_ext_cnt++;kfree (name);break ;
Signature · 1 line
2.39.5
Chao Yu
maintainerQuoted 23 lines · Daniel Yang
strcpy is deprecated. Kernel docs recommend replacing strcpy with strscpy. The function
strcpy()return value isn't used so there shouldn't be an issue replacing with the safer alternative strscpy.Signed-off-by Daniel Yang <[email protected]>---
V1 -> V2: handle strscpy errors, changed prefix to f2fsfs/f2fs/super.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-)fs/f2fs/super.c +0
-0@@ -5,6 +5,7 @@* Copyright (c) 2012 Samsung Electronics Co., Ltd. * http://www.samsung.com/ */ #include <linux/module.h> #include <linux/init.h> #include <linux/fs.h>
fs/f2fs/super.c static int parse_options(struct super_block *sb, char *options, bool is_remount) · line 1164
Quoted 7 lines
fs/f2fs/super.c +3
-1@@ -1158,7 +1159,10 @@ static int parse_options(struct super_block *sb, char *options, bool is_remount)break ; } -strcpy (ext[ext_cnt], name); +if (strscpy (ext[ext_cnt], name) == -E2BIG ) { +kfree (name); +return -EINVAL ;
How about?
ret = strscpy(ext[ext_cnt], name);
if (ret < 0) {
kfree(name);
return ret;
}fs/f2fs/super.c static int parse_options(struct super_block *sb, char *options, bool is_remount) · line 1197
Quoted 13 lines
fs/f2fs/super.c +5
-1+ }F2FS_OPTION (sbi).compress_ext_cnt++;kfree (name);break ;@@ -1187,7 +1191,10 @@ static int parse_options(struct super_block *sb, char *options, bool is_remount)break ; } -strcpy (noext[noext_cnt], name); +if (strscpy (noext[noext_cnt], name) == -E2BIG ) { +kfree (name); +return -EINVAL ; + }
Ditto
Thanks,
Quoted 3 lines
fs/f2fs/super.c +0
-0F2FS_OPTION (sbi).nocompress_ext_cnt++;kfree (name);break ;
Quoted 57 lines · Chao Yu
Quoted 23 lines · Daniel Yang
strcpy is deprecated. Kernel docs recommend replacing strcpy with strscpy. The function
strcpy()return value isn't used so there shouldn't be an issue replacing with the safer alternative strscpy.Signed-off-by Daniel Yang <[email protected]>---
V1 -> V2: handle strscpy errors, changed prefix to f2fsfs/f2fs/super.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-)fs/f2fs/super.c +0
-0@@ -5,6 +5,7 @@* Copyright (c) 2012 Samsung Electronics Co., Ltd. * http://www.samsung.com/ */ #include <linux/module.h> #include <linux/init.h> #include <linux/fs.h> fs/f2fs/super.c static int parse_options(struct super_block *sb, char *options, bool is_remount) · line 1164
Quoted 7 lines
fs/f2fs/super.c +3
-1@@ -1158,7 +1159,10 @@ static int parse_options(struct super_block *sb, char *options, bool is_remount)break ; } -strcpy (ext[ext_cnt], name); +if (strscpy (ext[ext_cnt], name) == -E2BIG ) { +kfree (name); +return -EINVAL ;How about?
ret =
strscpy(ext[ext_cnt], name);if (ret < 0) { kfree(name); return ret; }fs/f2fs/super.c static int parse_options(struct super_block *sb, char *options, bool is_remount) · line 1197
Quoted 13 lines
fs/f2fs/super.c +5
-1+ }F2FS_OPTION (sbi).compress_ext_cnt++;kfree (name);break ;@@ -1187,7 +1191,10 @@ static int parse_options(struct super_block *sb, char *options, bool is_remount)break ; } -strcpy (noext[noext_cnt], name); +if (strscpy (noext[noext_cnt], name) == -E2BIG ) { +kfree (name); +return -EINVAL ; + }Ditto
Quoted 6 lines
Thanks,
Quoted 3 lines
fs/f2fs/super.c +0
-0F2FS_OPTION (sbi).nocompress_ext_cnt++;kfree (name);break ;
Thanks for the feedback. That does look much cleaner. I've applied the changes and sent v3.
- Daniel