diff mbox series

[net] xfrm: replace deprecated strncpy with strscpy_pad

Message ID 20241113092058.189142-1-danielyangkang@gmail.com (mailing list archive)
State Awaiting Upstream
Delegated to: Netdev Maintainers
Headers show
Series [net] xfrm: replace deprecated strncpy with strscpy_pad | expand

Checks

Context Check Description
netdev/series_format success Single patches do not need cover letters
netdev/tree_selection success Clearly marked for net
netdev/ynl success Generated files up to date; no warnings/errors; no diff in generated;
netdev/fixes_present fail Series targets non-next tree, but doesn't contain any Fixes tags
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 3 this patch: 3
netdev/build_tools success No tools touched, skip
netdev/cc_maintainers success CCed 7 of 7 maintainers
netdev/build_clang success Errors and warnings before: 3 this patch: 3
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/deprecated_api success None detected
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success No Fixes tag
netdev/build_allmodconfig_warn success Errors and warnings before: 19 this patch: 19
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 8 lines checked
netdev/build_clang_rust success No Rust files in patch. Skipping build
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0
netdev/contest success net-next-2024-11-14--03-00 (tests: 782)

Commit Message

Daniel Yang Nov. 13, 2024, 9:20 a.m. UTC
The function strncpy is deprecated since it does not guarantee the
destination buffer is NULL terminated. Recommended replacement is
strscpy. The padded version was used to remain consistent with the other
strscpy_pad usage in the modified function.

Signed-off-by: Daniel Yang <danielyangkang@gmail.com>
---
 net/xfrm/xfrm_user.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Paolo Abeni Nov. 14, 2024, 10:34 a.m. UTC | #1
On 11/13/24 10:20, Daniel Yang wrote:
> The function strncpy is deprecated since it does not guarantee the
> destination buffer is NULL terminated. Recommended replacement is
> strscpy. The padded version was used to remain consistent with the other
> strscpy_pad usage in the modified function.
> 
> Signed-off-by: Daniel Yang <danielyangkang@gmail.com>
> ---
>  net/xfrm/xfrm_user.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/net/xfrm/xfrm_user.c b/net/xfrm/xfrm_user.c
> index e3b8ce898..085f68e35 100644
> --- a/net/xfrm/xfrm_user.c
> +++ b/net/xfrm/xfrm_user.c
> @@ -1089,7 +1089,7 @@ static int copy_to_user_auth(struct xfrm_algo_auth *auth, struct sk_buff *skb)
>  	if (!nla)
>  		return -EMSGSIZE;
>  	algo = nla_data(nla);
> -	strncpy(algo->alg_name, auth->alg_name, sizeof(algo->alg_name));
> +	strscpy_pad(algo->alg_name, auth->alg_name, sizeof(algo->alg_name));
>  
>  	if (redact_secret && auth->alg_key_len)
>  		memset(algo->alg_key, 0, (auth->alg_key_len + 7) / 8);

@Steffen, @Herbert: I think this should go via your tree despite the
prefix tag.

Please LMK otherwise!

Thanks,

Paolo
Steffen Klassert Nov. 14, 2024, 10:37 a.m. UTC | #2
On Thu, Nov 14, 2024 at 11:34:25AM +0100, Paolo Abeni wrote:
> On 11/13/24 10:20, Daniel Yang wrote:
> > The function strncpy is deprecated since it does not guarantee the
> > destination buffer is NULL terminated. Recommended replacement is
> > strscpy. The padded version was used to remain consistent with the other
> > strscpy_pad usage in the modified function.
> > 
> > Signed-off-by: Daniel Yang <danielyangkang@gmail.com>
> > ---
> >  net/xfrm/xfrm_user.c | 2 +-
> >  1 file changed, 1 insertion(+), 1 deletion(-)
> > 
> > diff --git a/net/xfrm/xfrm_user.c b/net/xfrm/xfrm_user.c
> > index e3b8ce898..085f68e35 100644
> > --- a/net/xfrm/xfrm_user.c
> > +++ b/net/xfrm/xfrm_user.c
> > @@ -1089,7 +1089,7 @@ static int copy_to_user_auth(struct xfrm_algo_auth *auth, struct sk_buff *skb)
> >  	if (!nla)
> >  		return -EMSGSIZE;
> >  	algo = nla_data(nla);
> > -	strncpy(algo->alg_name, auth->alg_name, sizeof(algo->alg_name));
> > +	strscpy_pad(algo->alg_name, auth->alg_name, sizeof(algo->alg_name));
> >  
> >  	if (redact_secret && auth->alg_key_len)
> >  		memset(algo->alg_key, 0, (auth->alg_key_len + 7) / 8);
> 
> @Steffen, @Herbert: I think this should go via your tree despite the
> prefix tag.

I'll take it into ipsec-next.

Thanks!
diff mbox series

Patch

diff --git a/net/xfrm/xfrm_user.c b/net/xfrm/xfrm_user.c
index e3b8ce898..085f68e35 100644
--- a/net/xfrm/xfrm_user.c
+++ b/net/xfrm/xfrm_user.c
@@ -1089,7 +1089,7 @@  static int copy_to_user_auth(struct xfrm_algo_auth *auth, struct sk_buff *skb)
 	if (!nla)
 		return -EMSGSIZE;
 	algo = nla_data(nla);
-	strncpy(algo->alg_name, auth->alg_name, sizeof(algo->alg_name));
+	strscpy_pad(algo->alg_name, auth->alg_name, sizeof(algo->alg_name));
 
 	if (redact_secret && auth->alg_key_len)
 		memset(algo->alg_key, 0, (auth->alg_key_len + 7) / 8);