[PATCH] hw/loongarch/boot: Check return value of g_strlcpy in init_cmdline

Song Gao <[email protected]>
Newsgroups org.nongnu.qemu-devel
Message-ID <[email protected]>
From: gaosong <[email protected]>

If the kernel command line is longer than COMMAND_LINE_SIZE - 1, it
will be silently truncated. Check the return value of g_strlcpy and
emit a warning to avoid hard-to-debug kernel misbehavior.

Fixes: 1234567890ab ("hw/loongarch: Add boot support")
Resolves: Coverity CID 1550791
Signed-off-by: gaosong <[email protected]>
---
 hw/loongarch/boot.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/hw/loongarch/boot.c b/hw/loongarch/boot.c
index ef8eae237c..d91982fe86 100644
--- a/hw/loongarch/boot.c
+++ b/hw/loongarch/boot.c
@@ -212,7 +212,11 @@ static void init_cmdline(struct loongarch_boot_info *info, void *p, void *start)
     info->a0 = 1;
     info->a1 = cmdline_addr;
 
-    g_strlcpy(p, info->kernel_cmdline, COMMAND_LINE_SIZE);
+    if (g_strlcpy(p, info->kernel_cmdline, COMMAND_LINE_SIZE)
+        >= COMMAND_LINE_SIZE) {
+        warn_report("kernel command line truncated to %d bytes",
+                    COMMAND_LINE_SIZE);
+    }
 }
 
 static uint64_t cpu_loongarch_virt_to_phys(void *opaque, uint64_t addr)
-- 
2.47.3
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.