Skip to content

Commit 9b4f2fe

Browse files
committed
Fix off-by-one error in bootargs parsing
This commit prevents null terminator at wrong position.
1 parent 436a2ed commit 9b4f2fe

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

src/riscv.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -318,10 +318,10 @@ static void load_dtb(char **ram_loc, vm_attr_t *attr)
318318
node = fdt_path_offset(dtb_buf, "/chosen");
319319
assert(node > 0);
320320

321-
len = strlen(bootargs) + 1;
322-
buf = malloc(len);
321+
len = strlen(bootargs);
322+
buf = malloc(len + 1);
323323
assert(buf);
324-
memcpy(buf, bootargs, len - 1);
324+
memcpy(buf, bootargs, len);
325325
buf[len] = 0;
326326
err = fdt_setprop(dtb_buf, node, "bootargs", buf, len + 1);
327327
if (err == -FDT_ERR_NOSPACE) {

0 commit comments

Comments
 (0)