[PATCH v1 1/2] tools: mkimage: fix stale data pointer in fit_import_data()
Aristo Chen
aristo.chen at canonical.com
Fri Jul 10 17:33:39 CEST 2026
The data pointer and the name of the external data property are
declared outside the loop over the image nodes, so their values leak
from one image into the next. An image node that carries data-size but
neither data-offset nor data-position then reuses the pointer of the
previously imported image: the previous image's data is written into
the node before the import aborts when it tries to delete an external
data property the node does not have. Since that abort path only prints
a debug message, mkimage fails without any indication of what is wrong.
The failure mode also depends on the order of the image nodes: when no
externally stored image precedes the malformed node, the stale pointer
is still NULL, so the import skips the node and the hashing stage
reports a proper error instead.
Move the declarations into the loop so that each image starts from a
clean state. A node without an external data reference is now skipped
consistently regardless of node order, and a malformed node is always
reported by the later processing stages with a proper error message.
Signed-off-by: Aristo Chen <aristo.chen at canonical.com>
---
tools/fit_image.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/tools/fit_image.c b/tools/fit_image.c
index 5831b07c090..7e59bc43b77 100644
--- a/tools/fit_image.c
+++ b/tools/fit_image.c
@@ -898,8 +898,6 @@ err:
static int fit_import_data(struct image_tool_params *params, const char *fname)
{
void *fdt, *old_fdt;
- void *data = NULL;
- const char *ext_data_prop = NULL;
int fit_size, new_size, size, data_base;
int fd;
struct stat sbuf;
@@ -941,6 +939,8 @@ static int fit_import_data(struct image_tool_params *params, const char *fname)
for (node = fdt_first_subnode(fdt, images);
node >= 0;
node = fdt_next_subnode(fdt, node)) {
+ const char *ext_data_prop = NULL;
+ void *data = NULL;
int buf_ptr;
int len;
--
2.43.0
More information about the U-Boot
mailing list