summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAristo Chen <[email protected]>2026-07-10 15:33:39 +0000
committerTom Rini <[email protected]>2026-07-23 13:42:49 -0600
commiteecc4148fe61a53fa1f4d16ffb453c3901fc704f (patch)
tree21f667a8449c88c528a96adc6393a87fd849e80b
parent9652e00aaa78c3435be33e534a8fae533ca1dc20 (diff)
tools: mkimage: fix stale data pointer in fit_import_data()
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 <[email protected]> Reviewed-by: Simon Glass <[email protected]>
-rw-r--r--tools/fit_image.c4
1 files 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;