boot: pxe_utils: Fix incorrect allocation of overlay_dir
PATCH v3 1/1 boot: pxe_utils: Fix incorrect allocation of overlay_dir
The function label_boot_extension() calls snprintf on a buffer overlay_dir. However, this buffer is not initialized properly. In the "if" branch it is initialized using a variable "len", which is smaller than the resulting buffer. In the "else" branch this variable is not initialized at all. This results in a crash when calling a "sysboot" command.
This commit fixes this issue.
--- boot/pxe_utils.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
boot/pxe_utils.c +4 -1
@@ -474,7 +474,7 @@ static void label_boot_extension(struct pxe_context *ctx, slash ="" ; dir_len =strlen (label->fdtdir) +strlen (slash) +1 ; - overlay_dir =calloc (1 , len); + overlay_dir =calloc (1 , dir_len);if (!overlay_dir)return ;
@@ -482,6 +482,9 @@ static void label_boot_extension(struct pxe_context *ctx, slash); }else { dir_len =2 ; + overlay_dir =calloc (1 , dir_len); +if (!overlay_dir) +return ;snprintf (overlay_dir, dir_len,"/" ); }
Signature · 1 line
2.43.0
Hi Surkov,
Quoted 11 lines · Surkov Kirill
[You don't often get email from [email protected]. Learn why this is important at https://aka.ms/LearnAboutSenderIdentification ]
The function
label_boot_extension()calls snprintf on a bufferoverlay_dir. However, this buffer is not initialized properly. In the "if" branch it is initialized using a variable "len", which is smaller than the resulting buffer. In the "else" branch this variable is not initialized at all. This results in a crash when calling a "sysboot" command.This commit fixes this issue.
I believe we already have a patch submitted for this issue:
https://lore.kernel.org/u-boot/[email protected]/T/#u
so please give that a try and a tested-by/reviewed-by there.
Cheers,
Quentin