]> git.ipfire.org Git - thirdparty/u-boot.git/commit
tools: mkimage: fix stale data pointer in fit_import_data()
authorAristo Chen <aristo.chen@canonical.com>
Fri, 10 Jul 2026 15:33:39 +0000 (15:33 +0000)
committerTom Rini <trini@konsulko.com>
Thu, 23 Jul 2026 19:42:49 +0000 (13:42 -0600)
commiteecc4148fe61a53fa1f4d16ffb453c3901fc704f
tree21f667a8449c88c528a96adc6393a87fd849e80b
parent9652e00aaa78c3435be33e534a8fae533ca1dc20
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 <aristo.chen@canonical.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
tools/fit_image.c