Skip to contentSkip to conversation

Staging: exfat: Avoid use of strcpy

PATCH Superseded Sandro Volery 2 participants 4 messages Sep 11, 2019 Staging

v2 of 5 Superseded Latest is v5 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 Staging: exfat: Avoid use of strcpy

Use strscpy instead of strcpy in exfat_core.c, and add a check for length that will return already known FFS_INVALIDPATH.

---
v2: Implement length check and return in one
v1: Original Patch

 drivers/staging/exfat/exfat_core.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/staging/exfat/exfat_core.c +2 -1
index da8c58149c35..4c40f1352848 100644
@@ -2964,7 +2964,8 @@ s32 resolve_path(struct inode *inode, char *path, struct chain_t *p_dir,
 	if (strlen(path) >= (MAX_NAME_LENGTH * MAX_CHARSET_SIZE))
 		return FFS_INVALIDPATH;
 
-	strcpy(name_buf, path);
+	if (strscpy(name_buf, path, sizeof(name_buf)) < 0)
+		return FFS_INVALIDPATH;
 
 	nls_cstring_to_uniname(sb, p_uniname, name_buf, &lossy);
 	if (lossy)
Signature · 1 line
2.23.0
#1 lore raw
Quoted 16 lines · Sandro Volery

Use strscpy instead of strcpy in exfat_core.c, and add a check for length that will return already known FFS_INVALIDPATH.

---
v2: Implement length check and return in one
v1: Original Patch

 drivers/staging/exfat/exfat_core.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/staging/exfat/exfat_core.c +0 -0
index da8c58149c35..4c40f1352848 100644

drivers/staging/exfat/exfat_core.c s32 resolve_path(struct inode *inode, char *path, struct chain_t *p_dir, · line 2964

Quoted 1 line
drivers/staging/exfat/exfat_core.c +0 -0
@@ -2964,7 +2964,8 @@ s32 resolve_path(struct inode *inode, char *path, struct chain_t *p_dir,
 	if (strlen(path) >= (MAX_NAME_LENGTH * MAX_CHARSET_SIZE))
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Delete this as it is no longer required.

drivers/staging/exfat/exfat_core.c s32 resolve_path(struct inode *inode, char *path, struct chain_t *p_dir, · line 2968

Quoted 5 lines
drivers/staging/exfat/exfat_core.c +2 -1
 		return FFS_INVALIDPATH;
 
-	strcpy(name_buf, path);
+	if (strscpy(name_buf, path, sizeof(name_buf)) < 0)
+		return FFS_INVALIDPATH;

regards,
dan carpenter

#2 lore raw
Quoted 16 lines · Dan Carpenter
Quoted 11 lines · Sandro Volery

Use strscpy instead of strcpy in exfat_core.c, and add a check for length that will return already known FFS_INVALIDPATH.

---
v2: Implement length check and return in one
v1: Original Patch
drivers/staging/exfat/exfat_core.c | 3 ++-

1 file changed, 2 insertions(+), 1 deletion(-)
Quoted 9 lines

drivers/staging/exfat/exfat_core.c s32 resolve_path(struct inode *inode, char *path, struct chain_t *p_dir, · line 2964

Quoted 6 lines
drivers/staging/exfat/exfat_core.c +0 -0
index da8c58149c35..4c40f1352848 100644
@@ -2964,7 +2964,8 @@ s32 resolve_path(struct inode *inode, char *path, struct chain_t *p_dir,
   if (strlen(path) >= (MAX_NAME_LENGTH * MAX_CHARSET_SIZE))
       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Delete this as it is no longer required.

Yep, saw it from Rasmus response too just now.. Dumb mistake. Will fix this this afternoon.

Sandro V

Quoted 6 lines
Quoted 5 lines
drivers/staging/exfat/exfat_core.c +2 -1
       return FFS_INVALIDPATH;
 
-    strcpy(name_buf, path);
+    if (strscpy(name_buf, path, sizeof(name_buf)) < 0)
+        return FFS_INVALIDPATH;
#3 lore raw
Quoted 26 lines · Sandro Volery
Quoted 16 lines · Dan Carpenter
Quoted 11 lines · Sandro Volery

Use strscpy instead of strcpy in exfat_core.c, and add a check for length that will return already known FFS_INVALIDPATH.

---
v2: Implement length check and return in one
v1: Original Patch
drivers/staging/exfat/exfat_core.c | 3 ++-

1 file changed, 2 insertions(+), 1 deletion(-)
Quoted 9 lines

drivers/staging/exfat/exfat_core.c s32 resolve_path(struct inode *inode, char *path, struct chain_t *p_dir, · line 2964

Quoted 6 lines
drivers/staging/exfat/exfat_core.c +0 -0
index da8c58149c35..4c40f1352848 100644
@@ -2964,7 +2964,8 @@ s32 resolve_path(struct inode *inode, char *path, struct chain_t *p_dir,
   if (strlen(path) >= (MAX_NAME_LENGTH * MAX_CHARSET_SIZE))
       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Delete this as it is no longer required.

Quoted 3 lines

Yep, saw it from Rasmus response too just now.. Dumb mistake. Will fix this this afternoon.

Or you could send it tomorrow. There is no rush.

regards,
dan carpenter