Skip to contentSkip to conversation

parse_options(): replace deprecated strcpy with strscpy

PATCH Superseded Daniel Yang 2 participants 3 messages Nov 6, 2024 – Nov 9, 2024 F2FS file system

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 parse_options(): 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.

---
 fs/f2fs/super.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
fs/f2fs/super.c +2 -2
index 87ab5696b..ee8861b95 100644
@@ -1158,7 +1158,7 @@ static int parse_options(struct super_block *sb, char *options, bool is_remount)
 				break;
 			}
 
-			strcpy(ext[ext_cnt], name);
+			strscpy(ext[ext_cnt], name);
 			F2FS_OPTION(sbi).compress_ext_cnt++;
 			kfree(name);
 			break;
@@ -1187,7 +1187,7 @@ static int parse_options(struct super_block *sb, char *options, bool is_remount)
 				break;
 			}
 
-			strcpy(noext[noext_cnt], name);
+			strscpy(noext[noext_cnt], name);
 			F2FS_OPTION(sbi).nocompress_ext_cnt++;
 			kfree(name);
 			break;
Signature · 1 line
2.39.5
maintainer
#1 lore raw
Quoted 3 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.

It's better to add "f2fs: " prefix for commit title.

Quoted 11 lines
---
  fs/f2fs/super.c | 4 ++--
  1 file changed, 2 insertions(+), 2 deletions(-)
fs/f2fs/super.c +0 -0
index 87ab5696b..ee8861b95 100644

fs/f2fs/super.c static int parse_options(struct super_block *sb, char *options, bool is_remount) · line 1161

Quoted 5 lines
fs/f2fs/super.c +1 -1
@@ -1158,7 +1158,7 @@ static int parse_options(struct super_block *sb, char *options, bool is_remount)
  				break;
  			}
 
-			strcpy(ext[ext_cnt], name);
+			strscpy(ext[ext_cnt], name);

Needs to handle return value of strscpy()?

fs/f2fs/super.c static int parse_options(struct super_block *sb, char *options, bool is_remount) · line 1190

Quoted 9 lines
fs/f2fs/super.c +1 -1
  			F2FS_OPTION(sbi).compress_ext_cnt++;
  			kfree(name);
  			break;
@@ -1187,7 +1187,7 @@ static int parse_options(struct super_block *sb, char *options, bool is_remount)
  				break;
  			}
 
-			strcpy(noext[noext_cnt], name);
+			strscpy(noext[noext_cnt], name);

Ditto,

Thanks,

Quoted 3 lines
fs/f2fs/super.c +0 -0
  			F2FS_OPTION(sbi).nocompress_ext_cnt++;
  			kfree(name);
  			break;
#2 lore raw
Quoted 34 lines · Chao Yu
Quoted 3 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.

It's better to add "f2fs: " prefix for commit title.

Quoted 11 lines
---
  fs/f2fs/super.c | 4 ++--
  1 file changed, 2 insertions(+), 2 deletions(-)
fs/f2fs/super.c +0 -0
index 87ab5696b..ee8861b95 100644

fs/f2fs/super.c static int parse_options(struct super_block *sb, char *options, bool is_remount) · line 1161

Quoted 5 lines
fs/f2fs/super.c +1 -1
@@ -1158,7 +1158,7 @@ static int parse_options(struct super_block *sb, char *options, bool is_remount)
                              break;
                      }
 
-                     strcpy(ext[ext_cnt], name);
+                     strscpy(ext[ext_cnt], name);

Needs to handle return value of strscpy()?

Quoted 7 lines
fs/f2fs/super.c +0 -0
                      F2FS_OPTION(sbi).compress_ext_cnt++;
                      kfree(name);
                      break;
@@ -1187,7 +1187,7 @@ static int parse_options(struct super_block *sb, char *options, bool is_remount)
                              break;
                      }
 
Quoted 11 lines

fs/f2fs/super.c static int parse_options(struct super_block *sb, char *options, bool is_remount) · line 1190

Quoted 2 lines
fs/f2fs/super.c +1 -1
-                     strcpy(noext[noext_cnt], name);
+                     strscpy(noext[noext_cnt], name);

Ditto,

Thanks,

Quoted 3 lines
fs/f2fs/super.c +0 -0
                      F2FS_OPTION(sbi).nocompress_ext_cnt++;
                      kfree(name);
                      break;

Ok, I've added the changes and sent a v2 of the patch. Lmk if there's any other issues.

- Daniel