keys: Replace deprecated strncpy in ecryptfs_fill_auth_tok
Subsystems (4)
PATCH 1/1 keys: Replace deprecated strncpy in ecryptfs_fill_auth_tok
strncpy() is deprecated for NUL-terminated destination buffers; use strscpy_pad() instead.
--- security/keys/encrypted-keys/ecryptfs_format.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
security/keys/encrypted-keys/ecryptfs_format.c +1 -2
@@ -54,8 +54,7 @@ int ecryptfs_fill_auth_tok(struct ecryptfs_auth_tok *auth_tok, auth_tok->version = (((uint16_t )(major <<8 ) &0xFF00 ) | ((uint16_t )minor &0x00FF )); auth_tok->token_type =ECRYPTFS_PASSWORD ; -strncpy ((char *)auth_tok->token.password.signature, key_desc, -ECRYPTFS_PASSWORD_SIG_SIZE ); +strscpy_pad (auth_tok->token.password.signature, key_desc); auth_tok->token.password.session_key_encryption_key_bytes =ECRYPTFS_MAX_KEY_BYTES ;/*
Signature · 1 line
2.51.0
Jarkko Sakkinen
maintainerQuoted 5 lines · Thorsten Blum
strncpy()is deprecated for NUL-terminated destination buffers; usestrscpy_pad()instead.Signed-off-by Thorsten Blum <[email protected]>
Deprecated or not but commit message still should have a better explanation :-) Sure there's also the link too that explains it all but still one should get the gist without cross-referencing into it.
It's a permanent amortized cost as everytime when revisiting this commit (e.g. over the course of bisecting or whatever), you need a web browser in order to make anything out of the message.
Quoted 21 lines
--- security/keys/encrypted-keys/ecryptfs_format.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)security/keys/encrypted-keys/ecryptfs_format.c +1
-2@@ -54,8 +54,7 @@ int ecryptfs_fill_auth_tok(struct ecryptfs_auth_tok *auth_tok, auth_tok->version = (((uint16_t )(major <<8 ) &0xFF00 ) | ((uint16_t )minor &0x00FF )); auth_tok->token_type =ECRYPTFS_PASSWORD ; -strncpy ((char *)auth_tok->token.password.signature, key_desc, -ECRYPTFS_PASSWORD_SIG_SIZE ); +strscpy_pad (auth_tok->token.password.signature, key_desc); auth_tok->token.password.session_key_encryption_key_bytes =ECRYPTFS_MAX_KEY_BYTES ;/* Signature · 1 line
2.51.0
BR, Jarkko
Quoted 2 lines · Thorsten Blum
strncpy()is deprecated for NUL-terminated destination buffers; usestrscpy_pad()instead.
Remember for strncpy->strscpy conversions, the commit message needs to include:
- how did you determine this was a NUL-terminated destination?
- how did you determine the need for padding or not?
- how do you know that final byte truncation is not a problem?
-Kees
Quoted 25 lines
Signed-off-by Thorsten Blum <[email protected]>--- security/keys/encrypted-keys/ecryptfs_format.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)security/keys/encrypted-keys/ecryptfs_format.c +1
-2@@ -54,8 +54,7 @@ int ecryptfs_fill_auth_tok(struct ecryptfs_auth_tok *auth_tok, auth_tok->version = (((uint16_t )(major <<8 ) &0xFF00 ) | ((uint16_t )minor &0x00FF )); auth_tok->token_type =ECRYPTFS_PASSWORD ; -strncpy ((char *)auth_tok->token.password.signature, key_desc, -ECRYPTFS_PASSWORD_SIG_SIZE ); +strscpy_pad (auth_tok->token.password.signature, key_desc); auth_tok->token.password.session_key_encryption_key_bytes =ECRYPTFS_MAX_KEY_BYTES ;/* Signature · 1 line
2.51.0
Signature · 1 line
Kees Cook