* [PATCH] tools/bootconfig: Fix null pointer when free buf
@ 2026-05-19 3:14 lihongtao
2026-05-19 15:04 ` Masami Hiramatsu
0 siblings, 1 reply; 2+ messages in thread
From: lihongtao @ 2026-05-19 3:14 UTC (permalink / raw)
To: Masami Hiramatsu; +Cc: linux-kernel, linux-trace-kernel, lihongtao
In show_xbc() and delete_xbc(), if load_xbc_from_initrd failed,
the buf may be NULL.
Fixes: 950313ebf79c ("tools: bootconfig: Add bootconfig command")
Signed-off-by: lihongtao <lihongtao@kylinos.cn>
---
tools/bootconfig/main.c | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/tools/bootconfig/main.c b/tools/bootconfig/main.c
index ddabde20585f..417d07a46f92 100644
--- a/tools/bootconfig/main.c
+++ b/tools/bootconfig/main.c
@@ -328,7 +328,8 @@ static int show_xbc(const char *path, bool list)
xbc_show_compact_tree();
ret = 0;
out:
- free(buf);
+ if (buf)
+ free(buf);
return ret;
}
@@ -360,7 +361,8 @@ static int delete_xbc(const char *path)
} /* Ignore if there is no boot config in initrd */
close(fd);
- free(buf);
+ if (buf)
+ free(buf);
return ret;
}
--
2.25.1
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] tools/bootconfig: Fix null pointer when free buf
2026-05-19 3:14 [PATCH] tools/bootconfig: Fix null pointer when free buf lihongtao
@ 2026-05-19 15:04 ` Masami Hiramatsu
0 siblings, 0 replies; 2+ messages in thread
From: Masami Hiramatsu @ 2026-05-19 15:04 UTC (permalink / raw)
To: lihongtao; +Cc: linux-kernel, linux-trace-kernel
On Tue, 19 May 2026 11:14:58 +0800
lihongtao <lihongtao@kylinos.cn> wrote:
> In show_xbc() and delete_xbc(), if load_xbc_from_initrd failed,
> the buf may be NULL.
NACK, because free() can handle NULL correctly. See free(3)
free()
The free() function frees the memory space pointed to by ptr, which must have been
returned by a previous call to malloc() or related functions. Otherwise, or if
ptr has already been freed, undefined behavior occurs. If ptr is NULL, no opera‐
tion is performed.
Thanks,
>
> Fixes: 950313ebf79c ("tools: bootconfig: Add bootconfig command")
> Signed-off-by: lihongtao <lihongtao@kylinos.cn>
> ---
> tools/bootconfig/main.c | 6 ++++--
> 1 file changed, 4 insertions(+), 2 deletions(-)
>
> diff --git a/tools/bootconfig/main.c b/tools/bootconfig/main.c
> index ddabde20585f..417d07a46f92 100644
> --- a/tools/bootconfig/main.c
> +++ b/tools/bootconfig/main.c
> @@ -328,7 +328,8 @@ static int show_xbc(const char *path, bool list)
> xbc_show_compact_tree();
> ret = 0;
> out:
> - free(buf);
> + if (buf)
> + free(buf);
>
> return ret;
> }
> @@ -360,7 +361,8 @@ static int delete_xbc(const char *path)
> } /* Ignore if there is no boot config in initrd */
>
> close(fd);
> - free(buf);
> + if (buf)
> + free(buf);
>
> return ret;
> }
> --
> 2.25.1
>
--
Masami Hiramatsu (Google) <mhiramat@kernel.org>
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-05-19 15:04 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-05-19 3:14 [PATCH] tools/bootconfig: Fix null pointer when free buf lihongtao
2026-05-19 15:04 ` Masami Hiramatsu
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox