Re: [PATCH] tools/bootconfig: Report initrd append failures

From: Masami Hiramatsu (Google)

Date: Tue Nov 24 2026 - 17:32:27 EST


On Fri, 20 Nov 2026 14:19:17 +0800, Zhu Jun <zhujun2@xxxxxxxxxxxxxxxxxxxx> wrote:
> The signed return value of write() is compared against a size_t.
> A negative return becomes an unsigned value and bypasses the error
> path, so applying a bootconfig can claim success without appending
> it. Check for a negative return before comparing the byte count.

Good catch!

>
> Fixes: e1cef2d4c379 ("tools/bootconfig: Align the bootconfig applied initrd image size to 4")

This bug was actually introduced one commit earlier in a995e6bc0524
("tools/bootconfig: Fix to check the write failure correctly"), which
changed `if (ret < 0)` to `if (ret < size + 8)` where
`size` was `u32` (unsigned). Commit e1cef2d4c379 kept the same bug when
switching `size + 8` to `size_t total_size`.

Let me pick it with changing Fixes tag.

Fixes: a995e6bc0524 ("tools/bootconfig: Fix to check the write failure
correctly")

Thanks,

> Signed-off-by: Zhu Jun <zhujun2@xxxxxxxxxxxxxxxxxxxx>
> ---
> tools/bootconfig/main.c | 16 +++++++++-------
> 1 file changed, 9 insertions(+), 7 deletions(-)

--
Masami Hiramatsu (Google) <mhiramat@xxxxxxxxxx>