boot: pxe_utils: Fix memory allocation issues in overlay_dir handling
authorKory Maincent (TI.com) <kory.maincent@bootlin.com>
Mon, 17 Nov 2025 15:23:07 +0000 (16:23 +0100)
committerTom Rini <trini@konsulko.com>
Sat, 22 Nov 2025 14:49:09 +0000 (08:49 -0600)
commit2d7eee5a55472f885474168acd3295d47a559755
treef8b008cbc7bffca658b014d46f5c158903b10eb6
parent8385ecc8eff91c45700040efbb08cba2ce6d3659
boot: pxe_utils: Fix memory allocation issues in overlay_dir handling

Fix two memory allocation bugs in label_boot_extension():

1. When label->fdtdir is not set, overlay_dir was used without any
   memory allocation.

2. When label->fdtdir is set, the allocation size was incorrect,
   using 'len' (just the fdtdir length) instead of 'dir_len' (which
   includes the trailing slash and null terminator).

Resolve both issues by moving the memory allocation and string
formatting outside the conditional block, resulting in clearer code
flow and correct sizing in all cases.

Closes: https://lists.denx.de/pipermail/u-boot/2025-November/602892.html
Addresses-Coverity-ID: 638558 Memory - illegal accesses (UNINIT)
Fixes: 935109cd9e97 ("boot: pxe_utils: Add extension board devicetree overlay support")
Signed-off-by: Kory Maincent (TI.com) <kory.maincent@bootlin.com>
Tested-by: Surkov Kirill <fanra3.tk@gmail.com>
boot/pxe_utils.c