Skip to content

Commit f7a1c02

Browse files
tobluxtyhicks
authored andcommitted
ecryptfs: Replace memcpy + manual NUL termination with strscpy
Use strscpy() to copy the NUL-terminated '->token.password.signature' and 'sig' to the destination buffers instead of using memcpy() followed by manual NUL terminations. Signed-off-by: Thorsten Blum <thorsten.blum@linux.dev> Signed-off-by: Tyler Hicks <code@tyhicks.com>
1 parent 7d9ebf3 commit f7a1c02

2 files changed

Lines changed: 4 additions & 7 deletions

File tree

fs/ecryptfs/debug.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
* Author(s): Michael A. Halcrow <mahalcro@us.ibm.com>
88
*/
99

10+
#include <linux/string.h>
1011
#include "ecryptfs_kernel.h"
1112

1213
/*
@@ -33,9 +34,7 @@ void ecryptfs_dump_auth_tok(struct ecryptfs_auth_tok *auth_tok)
3334
ECRYPTFS_PERSISTENT_PASSWORD) {
3435
ecryptfs_printk(KERN_DEBUG, " * persistent\n");
3536
}
36-
memcpy(sig, auth_tok->token.password.signature,
37-
ECRYPTFS_SIG_SIZE_HEX);
38-
sig[ECRYPTFS_SIG_SIZE_HEX] = '\0';
37+
strscpy(sig, auth_tok->token.password.signature);
3938
ecryptfs_printk(KERN_DEBUG, " * signature = [%s]\n", sig);
4039
}
4140
ecryptfs_printk(KERN_DEBUG, " * session_key.flags = [0x%x]\n",

fs/ecryptfs/keystore.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2458,8 +2458,7 @@ int ecryptfs_add_keysig(struct ecryptfs_crypt_stat *crypt_stat, char *sig)
24582458
if (!new_key_sig)
24592459
return -ENOMEM;
24602460

2461-
memcpy(new_key_sig->keysig, sig, ECRYPTFS_SIG_SIZE_HEX);
2462-
new_key_sig->keysig[ECRYPTFS_SIG_SIZE_HEX] = '\0';
2461+
strscpy(new_key_sig->keysig, sig);
24632462
/* Caller must hold keysig_list_mutex */
24642463
list_add(&new_key_sig->crypt_stat_list, &crypt_stat->keysig_list);
24652464

@@ -2479,9 +2478,8 @@ ecryptfs_add_global_auth_tok(struct ecryptfs_mount_crypt_stat *mount_crypt_stat,
24792478
if (!new_auth_tok)
24802479
return -ENOMEM;
24812480

2482-
memcpy(new_auth_tok->sig, sig, ECRYPTFS_SIG_SIZE_HEX);
2481+
strscpy(new_auth_tok->sig, sig);
24832482
new_auth_tok->flags = global_auth_tok_flags;
2484-
new_auth_tok->sig[ECRYPTFS_SIG_SIZE_HEX] = '\0';
24852483
mutex_lock(&mount_crypt_stat->global_auth_tok_list_mutex);
24862484
list_add(&new_auth_tok->mount_crypt_stat_list,
24872485
&mount_crypt_stat->global_auth_tok_list);

0 commit comments

Comments
 (0)