summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThorsten Blum <thorsten.blum@linux.dev>2025-12-19 22:32:33 +0100
committerTyler Hicks <code@tyhicks.com>2025-12-23 15:23:23 -0600
commite8fb5ec8934312df0a8f28b5514733acdf7ba722 (patch)
treeae60e1645d3871242e055382733314fdc2b9fa1a
parent0529a804095b22bf4fe8502d1a1eb09a25a5b954 (diff)
ecryptfs: Replace memcpy + NUL termination in ecryptfs_new_file_context
Use strscpy() to copy the NUL-terminated '->global_default_cipher_name' to the destination buffer instead of using memcpy() followed by a manual NUL termination. Remove the now-unused local variable 'cipher_name_len'. Signed-off-by: Thorsten Blum <thorsten.blum@linux.dev> Signed-off-by: Tyler Hicks <code@tyhicks.com>
-rw-r--r--fs/ecryptfs/crypto.c9
1 files changed, 2 insertions, 7 deletions
diff --git a/fs/ecryptfs/crypto.c b/fs/ecryptfs/crypto.c
index fa49d20521a4..c2ec043857f2 100644
--- a/fs/ecryptfs/crypto.c
+++ b/fs/ecryptfs/crypto.c
@@ -679,7 +679,6 @@ int ecryptfs_new_file_context(struct inode *ecryptfs_inode)
struct ecryptfs_mount_crypt_stat *mount_crypt_stat =
&ecryptfs_superblock_to_private(
ecryptfs_inode->i_sb)->mount_crypt_stat;
- int cipher_name_len;
int rc = 0;
ecryptfs_set_default_crypt_stat_vals(crypt_stat, mount_crypt_stat);
@@ -693,12 +692,8 @@ int ecryptfs_new_file_context(struct inode *ecryptfs_inode)
"to the inode key sigs; rc = [%d]\n", rc);
goto out;
}
- cipher_name_len =
- strlen(mount_crypt_stat->global_default_cipher_name);
- memcpy(crypt_stat->cipher,
- mount_crypt_stat->global_default_cipher_name,
- cipher_name_len);
- crypt_stat->cipher[cipher_name_len] = '\0';
+ strscpy(crypt_stat->cipher,
+ mount_crypt_stat->global_default_cipher_name);
crypt_stat->key_size =
mount_crypt_stat->global_default_cipher_key_size;
ecryptfs_generate_new_key(crypt_stat);