Re: [PATCH] hw/loongarch/boot: Check return value of g_strlcpy in init_cmdline
Bibo Mao <[email protected]> Thu, 6 Aug 2026 11:14:47 +0800
| Newsgroups | gmane.comp.emulators.qemu |
|---|---|
| Message-ID | <[email protected]> |
The value of COMMAND_LINE_SIZE in QEMU is different with Linux kernel, and linux kernel increases it with 4096. I think COMMAND_LINE_SIZE can be removed here, copy the whole string bootrom if it is smaller than bootrom size which is 1MB. Regards Bibo Mao On 2026/8/6 上午10:04, Song Gao wrote: > 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) >