Skip to contentSkip to conversation

mkimage: fix using long pathnames

PATCH New Sven Roederer 2 participants 5 messages Apr 27, 2020 – May 1, 2020

lore
Share & tools
lore
#0 lore raw

cover mkimage: fix using long pathnames

When running an buildbot with OpenWrt-CI I got the following error:

mkimage -f /var/lib/buildbot/slaves/slave/ipq40xx-generic/build/firmware/openwrt/ build_dir/target-arm_cortex-a7+neon-vfpv4_musl_eabi/linux-ipq40xx_generic/tmp/ freifunk-berlin-dev-daily-1907-f66973b-ipq40xx-generic-asus_map-ac2200-initramfs-fit-uImage.itb.its
/var/lib/buildbot/slaves/slave/ipq40xx-generic/build/firmware/openwrt/build_dir/
target-arm_cortex-a7+neon-vfpv4_musl_eabi/linux-ipq40xx_generic/tmp/ freifunk-berlin-dev-daily-1907-f66973b-ipq40xx-generic-asus_map-ac2200-initramfs-fit-uImage.itb.new
sh: 1: Syntax error: Unterminated quoted string

The syntax error is reported by the system()-call of fit_image.c as the cmd- variable get truncated when using such long pathnames for teh output and the FIT-file.
It's fixed by redefining the MKIMAGE_MAX_DTC_CMDLINE_LEN based on the size. of MKIMAGE_MAX_TMPFILE_LEN. Also a Warning will be printed when detecting that the cmd-variable has reached its maximal size.

Sven Roederer (2):
tools/mkimage: fix handling long filenames tools/fit-image: print a warning when cmd-line for dtc might be
truncated

 tools/fit_image.c | 4 ++++
 tools/mkimage.h   | 2 +-
 2 files changed, 5 insertions(+), 1 deletion(-)
Signature · 1 line
2.20.1
#1 lore raw

PATCH 1/2 tools/mkimage: fix handling long filenames

The cmdline for calling the dtc was cut-off when using long filenames (e.g. 245 bytes) for output-file and datafile of "-f" parameter.
For FIT-images cmd[MKIMAGE_MAX_DTC_CMDLINE_LEN] is declared (hardcoded 512 bytes), and contains some static values, the path of a tmpfile and a datafile. tmpfile is max MKIMAGE_MAX_TMPFILE_LEN (256) and datafile might be also this size. Having two very long pathname results in a truncation os the executed shell command, as the truncated datafile path will not be found.
Redefine MKIMAGE_MAX_DTC_CMDLINE_LEN to "2 * MKIMAGE_MAX_TMPFILE_LEN + 35 for the parameters.
This likely applies to the "-d" parameter, too.

---
 tools/mkimage.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/mkimage.h +1 -1
index 0254af59fb..9de94dbe99 100644
@@ -42,6 +42,7 @@ static inline ulong map_to_sysmem(void *ptr)
 #define MKIMAGE_TMPFILE_SUFFIX		".tmp"
 #define MKIMAGE_MAX_TMPFILE_LEN		256
 #define MKIMAGE_DEFAULT_DTC_OPTIONS	"-I dts -O dtb -p 500"
-#define MKIMAGE_MAX_DTC_CMDLINE_LEN	512
+#define MKIMAGE_MAX_DTC_CMDLINE_LEN	2 * MKIMAGE_MAX_TMPFILE_LEN + 35 
 /* 35 bytes for quotes, spaces, "-o", len(MKIMAGE_DEFAULT_DTC_OPTIONS), len(MKIMAGE_TMPFILE_SUFFIX) */
 

#endif /* _MKIIMAGE_H_ */

Signature · 1 line
2.20.1
#2 lore raw

PATCH 1/2 tools/mkimage: fix handling long filenames

Quoted 11 lines · Sven Roederer

The cmdline for calling the dtc was cut-off when using long filenames (e.g. 245 bytes) for output-file and datafile of "-f" parameter.
For FIT-images cmd[MKIMAGE_MAX_DTC_CMDLINE_LEN] is declared (hardcoded 512 bytes), and contains some static values, the path of a tmpfile and a datafile. tmpfile is max MKIMAGE_MAX_TMPFILE_LEN (256) and datafile might be also this size. Having two very long pathname results in a truncation os the executed shell command, as the truncated datafile path will not be found.
Redefine MKIMAGE_MAX_DTC_CMDLINE_LEN to "2 * MKIMAGE_MAX_TMPFILE_LEN + 35 for the parameters.
This likely applies to the "-d" parameter, too.

Quoted 1 line

Applied to u-boot/master, thanks!

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 659 bytes
Desc: not available
URL: <https://lists.denx.de/pipermail/u-boot/attachments/20200501/556e85bd/attachment.sig>
#3 lore raw

PATCH 2/2 tools/fit-image: print a warning when cmd-line for dtc might be truncated

In reply to Sven Roederer
---
 tools/fit_image.c | 4 ++++
 1 file changed, 4 insertions(+)
tools/fit_image.c +4 -0
index 4aeabbcfe9..88ff093d05 100644
@@ -17,6 +17,7 @@
 #include "fit_common.h"
 #include "mkimage.h"
 #include <image.h>
+#include <string.h>
 #include <stdarg.h>
 #include <version.h>
 #include <u-boot/crc.h>
@@ -744,6 +745,9 @@ static int fit_handle_file(struct image_tool_params *params)
 		snprintf(cmd, sizeof(cmd), "cp \"%s\" \"%s\"",
 			 params->imagefile, tmpfile);
 	}
+	if (strlen(cmd) >= MKIMAGE_MAX_DTC_CMDLINE_LEN - 1) {
+		fprintf(stderr, "WARNING: command-line for FIT creation might be truncated and will probably fail.\n");
+	}
 
 	if (*cmd && system(cmd) == -1) {
 		fprintf (stderr, "%s: system(%s) failed: %s\n",
Signature · 1 line
2.20.1
#4 lore raw

PATCH 2/2 tools/fit-image: print a warning when cmd-line for dtc might be truncated

Quoted 1 line · Sven Roederer

Applied to u-boot/master, thanks!

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 659 bytes
Desc: not available
URL: <https://lists.denx.de/pipermail/u-boot/attachments/20200501/9658973a/attachment.sig>