public inbox for kvm@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH kvmtool] riscv: Pass correct size to snprintf()
@ 2024-11-04 19:21 Björn Töpel
  2024-11-05  9:14 ` Andrew Jones
  2024-11-11 17:10 ` Will Deacon
  0 siblings, 2 replies; 3+ messages in thread
From: Björn Töpel @ 2024-11-04 19:21 UTC (permalink / raw)
  To: Will Deacon, Julien Thierry, Anup Patel, kvm, kvm-riscv
  Cc: Björn Töpel, Andrew Jones, linux-riscv, linux-kernel

From: Björn Töpel <bjorn@rivosinc.com>

The snprintf() function does not get the correct size argument passed,
when the FDT ISA string is built. Instead of adjusting the size for
each extension, the full size is passed for every iteration. Doing so
will make __snprinf_chk() bail out on glibc.

Adjust size for each iteration.

Fixes: 8aff29e1dafe ("riscv: Append ISA extensions to the device tree")
Signed-off-by: Björn Töpel <bjorn@rivosinc.com>
---
 riscv/fdt.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/riscv/fdt.c b/riscv/fdt.c
index 8189601f46de..85c8f95604f6 100644
--- a/riscv/fdt.c
+++ b/riscv/fdt.c
@@ -157,7 +157,7 @@ static void generate_cpu_nodes(void *fdt, struct kvm *kvm)
 					   isa_info_arr[i].name);
 				break;
 			}
-			pos += snprintf(cpu_isa + pos, CPU_ISA_MAX_LEN, "_%s",
+			pos += snprintf(cpu_isa + pos, CPU_ISA_MAX_LEN - pos, "_%s",
 					isa_info_arr[i].name);
 		}
 		cpu_isa[pos] = '\0';

base-commit: 3040b298156e4e2a82b27ac8db5bd63a72b3785b
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2024-11-11 17:10 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-11-04 19:21 [PATCH kvmtool] riscv: Pass correct size to snprintf() Björn Töpel
2024-11-05  9:14 ` Andrew Jones
2024-11-11 17:10 ` Will Deacon

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox