RISC-V: cpu: refactor deprecated strncpy
PATCH v2 1/1 RISC-V: cpu: refactor deprecated strncpy
strncpy is deprecated for use on NUL-terminated destination strings [1].
Favor not copying strings onto stack and instead use strings directly. This avoids hard-coding sizes and buffer lengths all together.
---
Changes in v2:
- Use strings directly instead of copying onto stack with strscpy (thanks Kees)
- Link to v1: https://lore.kernel.org/r/[email protected]
--- arch/riscv/kernel/cpu.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-)
arch/riscv/kernel/cpu.c +6 -6
@@ -271,21 +271,21 @@ static void print_isa(struct seq_file *f, const char *isa)static void print_mmu (struct seq_file *f) { -char sv_type[16 ]; +const char *sv_type;#ifdef CONFIG_MMU #if defined(CONFIG_32BIT ) -strncpy (sv_type,"sv32" ,5 ); + sv_type ="sv32" ;#elif defined(CONFIG_64BIT )if (pgtable_l5_enabled) -strncpy (sv_type,"sv57" ,5 ); + sv_type ="sv57" ;else if (pgtable_l4_enabled) -strncpy (sv_type,"sv48" ,5 ); + sv_type ="sv48" ;else -strncpy (sv_type,"sv39" ,5 ); + sv_type ="sv39" ;#endif #else -strncpy (sv_type,"none" ,5 ); + sv_type ="none" ;#endif /* CONFIG_MMU */ seq_printf (f,"mmu\t\t: %s\n" , sv_type); }
---
base-commit: 5d0c230f1de8c7515b6567d9afba1f196fb4e2f4
change-id: 20230801-arch-riscv-kernel-14a048cc6467
Best regards,
--
Justin Stitt <[email protected]>
Quoted 5 lines · Justin Stitt
strncpyis deprecated for use on NUL-terminated destination strings [1].Favor not copying strings onto stack and instead use strings directly. This avoids hard-coding sizes and buffer lengths all together.
Quoted 7 lines
Suggested-by Kees Cook <[email protected]>Signed-off-by Justin Stitt <[email protected]>---
Changes in v2:
- Use strings directly instead of copying onto stack withstrscpy(thanks Kees)
Yeah, that is what I was thinking of when I decried it as being horrid.
Thanks,
Conor.
_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv
Quoted 9 lines · Justin Stitt
strncpyis deprecated for use on NUL-terminated destination strings [1].Favor not copying strings onto stack and instead use strings directly. This avoids hard-coding sizes and buffer lengths all together.
Suggested-by Kees Cook <[email protected]>Signed-off-by Justin Stitt <[email protected]>
I like it! ;)
Signature · 1 line
Kees Cook
Quoted 6 lines · On Wed, 02 Aug 2023 13:36:03 PDT (-0700), [email protected] wrote:
Quoted 5 lines · Justin Stitt
strncpyis deprecated for use on NUL-terminated destination strings [1].Favor not copying strings onto stack and instead use strings directly. This avoids hard-coding sizes and buffer lengths all together.
Quoted 8 lines
Quoted 4 lines
Suggested-by Kees Cook <[email protected]>Signed-off-by Justin Stitt <[email protected]>I like it! ;)
Reviewed-by Kees Cook <[email protected]>
Thanks, I just queue it up for fixes (might take a bit to build test, I'm a bit backed up).
If you wanted to take it for some hardening thing, though -- otherwise it'll likely end up on my fixes later today.
_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv
Palmer Dabbelt
maintainerQuoted 16 lines · Palmer Dabbelt
Quoted 6 lines · On Wed, 02 Aug 2023 13:36:03 PDT (-0700), [email protected] wrote:
Quoted 5 lines · Justin Stitt
strncpyis deprecated for use on NUL-terminated destination strings [1].Favor not copying strings onto stack and instead use strings directly. This avoids hard-coding sizes and buffer lengths all together.
Quoted 8 lines
Quoted 4 lines
Suggested-by Kees Cook <[email protected]>Signed-off-by Justin Stitt <[email protected]>I like it! ;)
Reviewed-by Kees Cook <[email protected]>
Quoted 8 lines
Thanks, I just queue it up for fixes (might take a bit to build test, I'm a bit backed up).
Reviewed-by Palmer Dabbelt <[email protected]>Acked-by Palmer Dabbelt <[email protected]>If you wanted to take it for some hardening thing, though -- otherwise it'll likely end up on my fixes later today.
Sorry this is for-next as it's not a fix, I was just looking at other fixes. It's queued up aimed at for-next.
Quoted 20 lines · Palmer Dabbelt
Quoted 19 lines · Palmer Dabbelt
Quoted 6 lines · On Wed, 02 Aug 2023 13:36:03 PDT (-0700), [email protected] wrote:
Quoted 5 lines · Justin Stitt
strncpyis deprecated for use on NUL-terminated destination strings [1].Favor not copying strings onto stack and instead use strings directly. This avoids hard-coding sizes and buffer lengths all together.
Quoted 8 lines
Quoted 4 lines
Suggested-by Kees Cook <[email protected]>Signed-off-by Justin Stitt <[email protected]>I like it! ;)
Reviewed-by Kees Cook <[email protected]>Thanks, I just queue it up for fixes (might take a bit to build test, I'm a bit backed up).
Quoted 8 lines
Quoted 5 lines
Reviewed-by Palmer Dabbelt <[email protected]>Acked-by Palmer Dabbelt <[email protected]>If you wanted to take it for some hardening thing, though -- otherwise it'll likely end up on my fixes later today.
Sorry this is for-next as it's not a fix, I was just looking at other fixes. It's queued up aimed at for-next.
Awesome; thank you! :)
Signature · 1 line
Kees Cook
Palmer Dabbelt
AppliedQuoted 6 lines · Justin Stitt
strncpyis deprecated for use on NUL-terminated destination strings [1].Favor not copying strings onto stack and instead use strings directly. This avoids hard-coding sizes and buffer lengths all together.
Applied, thanks!
[1/1] RISC-V: cpu: refactor deprecated strncpy
https://git.kernel.org/palmer/c/12d61a1bc28e
Best regards,
Signature · 1 line
Palmer Dabbelt <[email protected]>
This patch was applied to riscv/linux.git (for-next) by Palmer Dabbelt <[email protected]>:
Hello:
This patch was applied to riscv/linux.git (for-next) by Palmer Dabbelt <[email protected]>:
Quoted 11 lines · On Wed, 02 Aug 2023 00:21:58 +0000 you wrote:
strncpyis deprecated for use on NUL-terminated destination strings [1].Favor not copying strings onto stack and instead use strings directly. This avoids hard-coding sizes and buffer lengths all together.
Suggested-by Kees Cook <[email protected]>Signed-off-by Justin Stitt <[email protected]>[...]
Here is the summary with links:
- [v2] RISC-V: cpu: refactor deprecated strncpy
https://git.kernel.org/riscv/c/12d61a1bc28e
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html