Skip to content

Commit 9c6dbb0

Browse files
DragonBlueprobimarko
authored andcommitted
busybox: fix regression for long long type dump support
Fix wrong output using '%d' format when byte count parameter is not given. Signed-off-by: Shiji Yang <[email protected]> Link: openwrt/openwrt#21013 Signed-off-by: Robert Marko <[email protected]>
1 parent 1db4155 commit 9c6dbb0

File tree

2 files changed

+69
-1
lines changed

2 files changed

+69
-1
lines changed

package/utils/busybox/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ include $(TOPDIR)/rules.mk
66

77
PKG_NAME:=busybox
88
PKG_VERSION:=1.37.0
9-
PKG_RELEASE:=5
9+
PKG_RELEASE:=6
1010
PKG_FLAGS:=essential
1111

1212
PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.bz2
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
From: Sven Wegener <[email protected]>
2+
Subject: [PATCH] libbb/dump: fix dumping of signed values without explicit
3+
size specifier
4+
5+
Message-ID: <[email protected]>
6+
7+
Commit e2287f99fe6f21fd6435ad04340170ad4ba5f6b3 added support for the 64
8+
bit signed format %lld, accidentally changing the default size of the %d
9+
format to eight bytes and producing the following:
10+
11+
root at openwrt:~# for i in $(seq 0 7); do hexdump -s $i -n 1 -e '"%d\n"' /dev/mtdblock0; done
12+
0
13+
0
14+
0
15+
0
16+
0
17+
0
18+
0
19+
0
20+
root at openwrt:~# for i in $(seq 0 7); do hexdump -s $i -n 1 -e '/4 "%d\n"' /dev/mtdblock0; done
21+
255
22+
0
23+
0
24+
16
25+
0
26+
0
27+
0
28+
0
29+
30+
With -n 1 the input is zero-padded. On big-endian, when the input is copied
31+
into the 64 bit variable, the input byte ends up in the highest byte. As the %d
32+
format only interprets the lower 32 bits, the input byte is lost during
33+
printing.
34+
35+
Depending on how the architecture passes 64 bit parameters, the same
36+
happens on little-endian as well. x86 (little-endian) works correctly,
37+
but MIPS experiences the same behavior on big-endian and little-endian.
38+
39+
Fixes: e2287f99fe6f21fd6435ad04340170ad4ba5f6b3
40+
See: https://github.com/openwrt/openwrt/issues/18808
41+
Signed-off-by: Sven Wegener <[email protected]>
42+
---
43+
libbb/dump.c | 7 ++++---
44+
1 file changed, 4 insertions(+), 3 deletions(-)
45+
46+
--- a/libbb/dump.c
47+
+++ b/libbb/dump.c
48+
@@ -192,16 +192,17 @@ static NOINLINE void rewrite(priv_dumper
49+
if (*p1 == 'l') { /* %lld etc */
50+
++p2;
51+
++p1;
52+
- }
53+
+ byte_count_str = "\010\004\002\001";
54+
+ } else {
55+
DO_INT_CONV:
56+
+ byte_count_str = "\004\002\001";
57+
+ }
58+
e = strchr(int_convs, *p1); /* "diouxX"? */
59+
if (!e)
60+
goto DO_BAD_CONV_CHAR;
61+
pr->flags = F_INT;
62+
- byte_count_str = "\010\004\002\001";
63+
if (e > int_convs + 1) { /* not d or i? */
64+
pr->flags = F_UINT;
65+
- byte_count_str++;
66+
}
67+
goto DO_BYTE_COUNT;
68+
} else

0 commit comments

Comments
 (0)