lkml.org 
[lkml]   [2023]   [Jan]   [9]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
Date
From
Subject[PATCH linux-next] Squashfs: use strscpy() to instead of strncpy()
From: Xu Panda <xu.panda@zte.com.cn>

The implementation of strscpy() is more robust and safer.
That's now the recommended way to copy NUL-terminated strings.

Signed-off-by: Xu Panda <xu.panda@zte.com.cn>
Signed-off-by: Yang Yang <yang.yang29@zte.com.cn>
---
fs/squashfs/namei.c | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/fs/squashfs/namei.c b/fs/squashfs/namei.c
index 11e4539b9eae..6c4704ba8f42 100644
--- a/fs/squashfs/namei.c
+++ b/fs/squashfs/namei.c
@@ -80,8 +80,7 @@ static int get_dir_index_using_name(struct super_block *sb,
}

str = &index->name[SQUASHFS_NAME_LEN + 1];
- strncpy(str, name, len);
- str[len] = '\0';
+ strscpy(str, name, len + 1);

for (i = 0; i < i_count; i++) {
err = squashfs_read_metadata(sb, index, &index_start,
--
2.15.2
\
 
 \ /
  Last update: 2023-03-26 23:33    [W:0.035 / U:0.492 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site