Skip to content

Commit e8fb5ec

Browse files
tobluxtyhicks
authored andcommitted
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>
1 parent 0529a80 commit e8fb5ec

1 file changed

Lines changed: 2 additions & 7 deletions

File tree

fs/ecryptfs/crypto.c

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -679,7 +679,6 @@ int ecryptfs_new_file_context(struct inode *ecryptfs_inode)
679679
struct ecryptfs_mount_crypt_stat *mount_crypt_stat =
680680
&ecryptfs_superblock_to_private(
681681
ecryptfs_inode->i_sb)->mount_crypt_stat;
682-
int cipher_name_len;
683682
int rc = 0;
684683

685684
ecryptfs_set_default_crypt_stat_vals(crypt_stat, mount_crypt_stat);
@@ -693,12 +692,8 @@ int ecryptfs_new_file_context(struct inode *ecryptfs_inode)
693692
"to the inode key sigs; rc = [%d]\n", rc);
694693
goto out;
695694
}
696-
cipher_name_len =
697-
strlen(mount_crypt_stat->global_default_cipher_name);
698-
memcpy(crypt_stat->cipher,
699-
mount_crypt_stat->global_default_cipher_name,
700-
cipher_name_len);
701-
crypt_stat->cipher[cipher_name_len] = '\0';
695+
strscpy(crypt_stat->cipher,
696+
mount_crypt_stat->global_default_cipher_name);
702697
crypt_stat->key_size =
703698
mount_crypt_stat->global_default_cipher_key_size;
704699
ecryptfs_generate_new_key(crypt_stat);

0 commit comments

Comments
 (0)