[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <c7dbeaf7-ab93-4b4f-904c-99d42a83a83d@amd.com>
Date: Tue, 8 Apr 2025 14:18:12 -0700
From: "Nelson, Shannon" <shannon.nelson@....com>
To: Pranav Tyagi <pranav.tyagi03@...il.com>, davem@...emloft.net,
dsahern@...nel.org, edumazet@...gle.com, kuba@...nel.org, pabeni@...hat.com,
horms@...nel.org, skhan@...uxfoundation.org, netdev@...r.kernel.org,
linux-rdma@...r.kernel.org, rds-devel@....oracle.com,
linux-kernel@...r.kernel.org, linux-kernel-mentees@...ts.linux.dev
Subject: Re: [PATCH] net: rds: replace strncpy with memcpy
On 4/8/2025 12:41 PM, Pranav Tyagi wrote:
>
> Replace deprecated strncpy() function with memcpy()
I suspect that strtomem() is a better answer here than a raw memcpy() -
it already has all the strnlen() and min() stuff baked into it, along
with some other compile-time checking.
> as the destination buffer is length bounded
> and not required to be NUL-terminated
Are you sure that null-termination is not required? I'm not familiar
with this bit of code, but the definitions of both of the .transport[]
fields do say /* null term ascii */
sln
>
> Signed-off-by: Pranav Tyagi <pranav.tyagi03@...il.com>
> ---
> net/rds/connection.c | 6 ++----
> 1 file changed, 2 insertions(+), 4 deletions(-)
>
> diff --git a/net/rds/connection.c b/net/rds/connection.c
> index c749c5525b40..3718c3edb32e 100644
> --- a/net/rds/connection.c
> +++ b/net/rds/connection.c
> @@ -749,8 +749,7 @@ static int rds_conn_info_visitor(struct rds_conn_path *cp, void *buffer)
> cinfo->laddr = conn->c_laddr.s6_addr32[3];
> cinfo->faddr = conn->c_faddr.s6_addr32[3];
> cinfo->tos = conn->c_tos;
> - strncpy(cinfo->transport, conn->c_trans->t_name,
> - sizeof(cinfo->transport));
> + memcpy(cinfo->transport, conn->c_trans->t_name, min(sizeof(cinfo->transport), strnlen(conn->c_trans->t_name, sizeof(cinfo->transport))));
> cinfo->flags = 0;
>
> rds_conn_info_set(cinfo->flags, test_bit(RDS_IN_XMIT, &cp->cp_flags),
> @@ -775,8 +774,7 @@ static int rds6_conn_info_visitor(struct rds_conn_path *cp, void *buffer)
> cinfo6->next_rx_seq = cp->cp_next_rx_seq;
> cinfo6->laddr = conn->c_laddr;
> cinfo6->faddr = conn->c_faddr;
> - strncpy(cinfo6->transport, conn->c_trans->t_name,
> - sizeof(cinfo6->transport));
> + memcpy(cinfo6->transport, conn->c_trans->t_name, min(sizeof(cinfo6->transport), strnlen(conn->c_trans->t_name, sizeof(cinfo6->transport))));
> cinfo6->flags = 0;
>
> rds_conn_info_set(cinfo6->flags, test_bit(RDS_IN_XMIT, &cp->cp_flags),
> --
> 2.49.0
>
>
Powered by blists - more mailing lists