net/rds: Replace deprecated strncpy() with strscpy_pad()
Subsystems (4)
PATCH 1/1 net/rds: Replace deprecated strncpy() with strscpy_pad()
strncpy() is deprecated for NUL-terminated destination buffers. Use strscpy_pad() instead and remove the manual NUL-termination.
Compile-tested only.
--- net/rds/stats.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
net/rds/stats.c +1 -2
@@ -89,8 +89,7 @@ void rds_stats_info_copy(struct rds_info_iterator *iter,for (i =0 ; i < nr; i++) {BUG_ON (strlen (names[i]) >=sizeof (ctr.name)); -strncpy (ctr.name, names[i],sizeof (ctr.name) -1 ); - ctr.name[sizeof (ctr.name) -1 ] ='\0' ; +strscpy_pad (ctr.name, names[i]); ctr.value = values[i];rds_info_copy (iter, &ctr,sizeof (ctr));
Signature · 1 line
2.48.1
Quoted 2 lines · Thorsten Blum
strncpy()is deprecated for NUL-terminated destination buffers. Usestrscpy_pad()instead and remove the manual NUL-termination.
When doing these conversions, please describe two aspects of conversions:
- Why is it safe to be NUL terminated
- Why is it safe to be/not-be NUL-padded
In this case, the latter needs examination. Looking at how ctr is used, it is memcpy()ed later, which means this string MUST be NUL padded or it will leak stack memory contents.
So, please use strscpy_pad() here. :)
-Kees
Quoted 28 lines
Compile-tested only.
Signed-off-by Thorsten Blum <[email protected]>--- net/rds/stats.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)net/rds/stats.c +1
-2@@ -89,8 +89,7 @@ void rds_stats_info_copy(struct rds_info_iterator *iter,for (i =0 ; i < nr; i++) {BUG_ON (strlen (names[i]) >=sizeof (ctr.name)); -strncpy (ctr.name, names[i],sizeof (ctr.name) -1 ); - ctr.name[sizeof (ctr.name) -1 ] ='\0' ; +strscpy_pad (ctr.name, names[i]); ctr.value = values[i];rds_info_copy (iter, &ctr,sizeof (ctr));Signature · 1 line
2.48.1
Signature · 1 line
Kees Cook
Quoted 7 lines · Kees Cook
Quoted 2 lines · Thorsten Blum
strncpy()is deprecated for NUL-terminated destination buffers. Usestrscpy_pad()instead and remove the manual NUL-termination.When doing these conversions, please describe two aspects of conversions:
Quoted 8 lines
- Why is it safe to be NUL terminated
- Why is it safe to be/not-be NUL-paddedIn this case, the latter needs examination. Looking at how ctr is used, it is memcpy()ed later, which means this string MUST be NUL padded or it will leak stack memory contents.
So, please use
strscpy_pad()here. :)
I am using strscpy_pad() here already because of the NUL-padding.
Did you just miss that?
Thanks,
Thorsten
Kees Cook
Reviewed-byQuoted 15 lines · Thorsten Blum
Quoted 14 lines · Kees Cook
Quoted 2 lines · Thorsten Blum
strncpy()is deprecated for NUL-terminated destination buffers. Usestrscpy_pad()instead and remove the manual NUL-termination.When doing these conversions, please describe two aspects of conversions:
- Why is it safe to be NUL terminated
- Why is it safe to be/not-be NUL-paddedIn this case, the latter needs examination. Looking at how ctr is used, it is memcpy()ed later, which means this string MUST be NUL padded or it will leak stack memory contents.
Quoted 5 lines
Quoted 1 line
So, please use
strscpy_pad()here. :)I am using
strscpy_pad()here already because of the NUL-padding.Did you just miss that?
Well that's embarrassing. Yes, I must need stronger glasses. *sigh* Apologies for the noise!
Signature · 1 line
Kees Cook
Quoted 17 lines · Thorsten Blum
strncpy()is deprecated for NUL-terminated destination buffers. Usestrscpy_pad()instead and remove the manual NUL-termination.Compile-tested only.
Signed-off-by Thorsten Blum <[email protected]>--- net/rds/stats.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)net/rds/stats.c +0
-0
net/rds/stats.c void rds_stats_info_copy(struct rds_info_iterator *iter, · line 94
Quoted 8 lines
net/rds/stats.c +1
-2@@ -89,8 +89,7 @@ void rds_stats_info_copy(struct rds_info_iterator *iter,for (i =0 ; i < nr; i++) {BUG_ON (strlen (names[i]) >=sizeof (ctr.name)); -strncpy (ctr.name, names[i],sizeof (ctr.name) -1 ); - ctr.name[sizeof (ctr.name) -1 ] ='\0' ; +strscpy_pad (ctr.name, names[i]); ctr.value = values[i];
Looks ok to me. Thanks Thorsten!
Quoted 1 line
net/rds/stats.c +0
-0rds_info_copy (iter, &ctr,sizeof (ctr));
Allison Henderson
Tested-byQuoted 5 lines · Allison Henderson
Quoted 4 lines · Thorsten Blum
strncpy()is deprecated for NUL-terminated destination buffers. Usestrscpy_pad()instead and remove the manual NUL-termination.Compile-tested only.
I went ahead and tested this for you, and it looks fine. So, you can go ahead and remove the "Compiled-tested only" and add:
Thank you!
Allison
Quoted 26 lines
Quoted 13 lines
Signed-off-by Thorsten Blum <[email protected]>--- net/rds/stats.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)net/rds/stats.c +0
-0net/rds/stats.c void rds_stats_info_copy(struct rds_info_iterator *iter, · line 94
Quoted 8 lines
net/rds/stats.c +1
-2@@ -89,8 +89,7 @@ void rds_stats_info_copy(struct rds_info_iterator *iter,for (i =0 ; i < nr; i++) {BUG_ON (strlen (names[i]) >=sizeof (ctr.name)); -strncpy (ctr.name, names[i],sizeof (ctr.name) -1 ); - ctr.name[sizeof (ctr.name) -1 ] ='\0' ; +strscpy_pad (ctr.name, names[i]); ctr.value = values[i];Looks ok to me. Thanks Thorsten!
Reviewed-by Allison Henderson <[email protected]>Quoted 1 line
net/rds/stats.c +0
-0rds_info_copy (iter, &ctr,sizeof (ctr));
This patch was applied to netdev/net-next.git (main) by Jakub Kicinski <[email protected]>:
Hello:
This patch was applied to netdev/net-next.git (main) by Jakub Kicinski <[email protected]>:
Quoted 10 lines · On Wed, 19 Feb 2025 23:47:31 +0100 you wrote:
strncpy()is deprecated for NUL-terminated destination buffers. Usestrscpy_pad()instead and remove the manual NUL-termination.Compile-tested only.
Signed-off-by Thorsten Blum <[email protected]>[...]
Here is the summary with links:
- [net-next] net/rds: Replace deprecated strncpy() with strscpy_pad()
https://git.kernel.org/netdev/net-next/c/c451715d78e3
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html