Skip to content

Commit 195c2ce

Browse files
grischehauke
authored andcommitted
build: fix image headers silently truncated with uutils coreutils
Build/elx-header and Build/znet-header convert a hex string into \xHH escape sequences using `fold -s2`. This relies on the obsolete -WIDTH option syntax of GNU fold, which parses "-s2" as "-s -2". uutils coreutils does not support this syntax and fails with: error: unexpected argument '-2' found tip: to pass '-2' as a value, use '-- -2' Since fold writes nothing to stdout in this case, the command substitution expands to an empty string. The following `dd bs=N count=1 conv=sync` then writes zero bytes, because conv=sync only pads partial input blocks and never pads empty input. The header field is dropped entirely, and all subsequent fields move to lower offsets. The build still succeeds, because the failure happens inside the subshell which is then handed to echo. The malformed images are only rejected when a device tries to boot them. For example, on the Zyxel WSM20, the missing payload size field in the znet-header moves the 0x12345678 magic and the payload to unexpected offsets. The bootloader then rejects the image, even though sysupgrade accepted it. This affects all builds on Ubuntu 25.10 and later, because these releases use uutils coreutils by default. Replace `fold -s2` with `fold -w2`, which is the documented way to set the line width and produces identical output with GNU fold. Affected devices: - Build/znet-header is used in all images of the Zyxel WSM20 and the ELECOM WRC-X1800GS - Build/elx-header is used in the factory images of the ELECOM WAB-I1750-PS, WAB-S1167-PS, WAB-S600-PS, WRC-2533GHBK-I and WRC-2533GHBK2-T, the I-O DATA WN-AC1167GR, WN-AC733GR3 and WNPR2600G, the Edimax RA21S and RG21S, and the D-Link DAP-X1860 A1 Signed-off-by: Grische <github@grische.xyz> Assisted-by: Claude:claude-opus-5 Link: openwrt/openwrt#25410 Signed-off-by: Hauke Mehrtens <hauke@hauke-m.de>
1 parent db9616b commit 195c2ce

2 files changed

Lines changed: 3 additions & 3 deletions

File tree

‎include/image-commands.mk‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -407,9 +407,9 @@ define Build/elx-header
407407
hw_id="$(hw_id)"; \
408408
echo -ne "\x$${hw_id:0:2}\x$${hw_id:2:2}\x$${hw_id:4:2}\x$${hw_id:6:2}" | \
409409
dd bs=20 count=1 conv=sync; \
410-
echo -ne "$$(printf '%08x' $$(stat -c%s $@) | fold -s2 | xargs -I {} echo \\x{} | tr -d '\n')" | \
410+
echo -ne "$$(printf '%08x' $$(stat -c%s $@) | fold -w2 | xargs -I {} echo \\x{} | tr -d '\n')" | \
411411
dd bs=8 count=1 conv=sync; \
412-
echo -ne "$$($(MKHASH) md5 $@ | fold -s2 | xargs -I {} echo \\x{} | tr -d '\n')" | \
412+
echo -ne "$$($(MKHASH) md5 $@ | fold -w2 | xargs -I {} echo \\x{} | tr -d '\n')" | \
413413
dd bs=58 count=1 conv=sync; \
414414
) > $(KDIR)/tmp/$(DEVICE_NAME).header
415415
-$(call Build/xor-image,-p $(xor_pattern) -x) \

‎target/linux/ramips/image/mt7621.mk‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ define Build/znet-header
184184
payload_size_crc="$$(dd if=$@ ibs=1 count=$$payload_len 2>/dev/null | gzip -c | \
185185
tail -c 8 | od -An -N4 -tx4 --endian big | tr -d ' \n')"; \
186186
echo -ne "$(magic)" | dd bs=4 count=1 conv=sync 2>/dev/null; \
187-
echo -ne "$$(printf '%08x' $$(stat -c%s $@) | fold -s2 | xargs -I {} echo \\x{} | tac | tr -d '\n')" | \
187+
echo -ne "$$(printf '%08x' $$(stat -c%s $@) | fold -w2 | xargs -I {} echo \\x{} | tac | tr -d '\n')" | \
188188
dd bs=4 count=1 conv=sync 2>/dev/null; \
189189
echo -ne "$$(echo $$data_size_crc | sed 's/../\\x&/g')" | \
190190
dd bs=4 count=1 conv=sync 2>/dev/null; \

0 commit comments

Comments
 (0)