busybox: fix regression for long long type dump support
authorShiji Yang <[email protected]>
Mon, 1 Dec 2025 16:06:45 +0000 (00:06 +0800)
committerRobert Marko <[email protected]>
Thu, 4 Dec 2025 11:15:59 +0000 (12:15 +0100)
Fix wrong output using '%d' format when byte count parameter is not
given.

Signed-off-by: Shiji Yang <[email protected]>
Link: https://github.com/openwrt/openwrt/pull/21013
Signed-off-by: Robert Marko <[email protected]>
package/utils/busybox/Makefile
package/utils/busybox/patches/100-libbb-dump-fix-dumping-of-signed-values-without-expl.patch [new file with mode: 0644]

index 63c1dceee3c9baf63f5ed786bde313430ad26c47..e5b7c2c7801c73046e29979a08867a66c78c2f72 100644 (file)
@@ -6,7 +6,7 @@ include $(TOPDIR)/rules.mk
 
 PKG_NAME:=busybox
 PKG_VERSION:=1.37.0
-PKG_RELEASE:=5
+PKG_RELEASE:=6
 PKG_FLAGS:=essential
 
 PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.bz2
diff --git a/package/utils/busybox/patches/100-libbb-dump-fix-dumping-of-signed-values-without-expl.patch b/package/utils/busybox/patches/100-libbb-dump-fix-dumping-of-signed-values-without-expl.patch
new file mode 100644 (file)
index 0000000..665dc60
--- /dev/null
@@ -0,0 +1,68 @@
+From: Sven Wegener <[email protected]>
+Subject: [PATCH] libbb/dump: fix dumping of signed values without explicit
+ size specifier
+
+Message-ID: <[email protected]>
+
+Commit e2287f99fe6f21fd6435ad04340170ad4ba5f6b3 added support for the 64
+bit signed format %lld, accidentally changing the default size of the %d
+format to eight bytes and producing the following:
+
+root at openwrt:~# for i in $(seq 0 7); do hexdump -s $i -n 1 -e '"%d\n"' /dev/mtdblock0; done
+0
+0
+0
+0
+0
+0
+0
+0
+root at openwrt:~# for i in $(seq 0 7); do hexdump -s $i -n 1 -e '/4 "%d\n"' /dev/mtdblock0; done
+255
+0
+0
+16
+0
+0
+0
+0
+
+With -n 1 the input is zero-padded. On big-endian, when the input is copied
+into the 64 bit variable, the input byte ends up in the highest byte. As the %d
+format only interprets the lower 32 bits, the input byte is lost during
+printing.
+
+Depending on how the architecture passes 64 bit parameters, the same
+happens on little-endian as well. x86 (little-endian) works correctly,
+but MIPS experiences the same behavior on big-endian and little-endian.
+
+Fixes: e2287f99fe6f21fd6435ad04340170ad4ba5f6b3
+See: https://github.com/openwrt/openwrt/issues/18808
+Signed-off-by: Sven Wegener <[email protected]>
+---
+ libbb/dump.c | 7 ++++---
+ 1 file changed, 4 insertions(+), 3 deletions(-)
+
+--- a/libbb/dump.c
++++ b/libbb/dump.c
+@@ -192,16 +192,17 @@ static NOINLINE void rewrite(priv_dumper
+                               if (*p1 == 'l') { /* %lld etc */
+                                       ++p2;
+                                       ++p1;
+-                              }
++                                      byte_count_str = "\010\004\002\001";
++                              } else {
+  DO_INT_CONV:
++                                      byte_count_str = "\004\002\001";
++                              }
+                               e = strchr(int_convs, *p1); /* "diouxX"? */
+                               if (!e)
+                                       goto DO_BAD_CONV_CHAR;
+                               pr->flags = F_INT;
+-                              byte_count_str = "\010\004\002\001";
+                               if (e > int_convs + 1) { /* not d or i? */
+                                       pr->flags = F_UINT;
+-                                      byte_count_str++;
+                               }
+                               goto DO_BYTE_COUNT;
+                       } else