Busybox hexdump bug

For discussions about programming, programming questions/advice, and projects that don't really have anything to do with Puppy.
Post Reply
Message
Author
User avatar
MochiMoppel
Posts: 2084
Joined: Wed 26 Jan 2011, 09:06
Location: Japan

Busybox hexdump bug

#1 Post by MochiMoppel »

Hexdump can convert control characters into their backslash equivalents but there seems to be a problem with the form feed character (hex 0C)

Below example pipes a string of 3 characters to hexdump: backspace (x08) newline (x0a) and form feed (x0c)

Hexdump's "%_u" format translates this string correctly to bs lf and ff
However the "%_c" format translates it to \b \n and \b
And that's wrong. The backslash escape sequence of form feed is \f and not \b
My BusyBox version v1.21.0. may be too old. Has this been corrected? Does this bug exist in the full version (which I don't have)?

Code: Select all

#!/bin/bash
echo -en "\x08\x0A\x0C" | hexdump  -e '1 "%_u\n"'
echo
echo -en "\x08\x0A\x0C" | hexdump  -e '1 "%_c\n"'

User avatar
fredx181
Posts: 4448
Joined: Wed 11 Dec 2013, 12:37
Location: holland

#2 Post by fredx181 »

Hi mochimoppel, on Ubuntu Bionic, busybox version 1.27.2, it is correct:

Code: Select all

root@live64:~# echo -en "\x08\x0A\x0C" | busybox hexdump  -e '1 "%_c\n"'
\b
\n
\f
On Debian Stretch, busybox version 1.22.1, it's incorrect, same as your output.

Fred

User avatar
misko_2083
Posts: 114
Joined: Tue 08 Nov 2016, 13:42

Re: Busybox hexdump bug

#3 Post by misko_2083 »

busybox 1.22.1 busybox hexdump: b

Code: Select all

echo -en "\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0A\x0B\x0C\x0D" | busybox hexdump  -e '1 "%_c\n"' 
\0
001
002
003
004
005
006
\a
\b
\t
\n
\v
\b
\r
busybox 1.22.1 busybox od: f

Code: Select all

echo -en "\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0A\x0B\x0C\x0D" | busybox od -An -tc -w1 | sed -e 's/^[ \t]*//'
\0
001
002
003
004
005
006
\a
\b
\t
\n
\v
\f
\r

User avatar
drunkjedi
Posts: 882
Joined: Mon 25 May 2015, 02:50

Re: Busybox hexdump bug

#4 Post by drunkjedi »

MochiMoppel wrote:Hexdump can convert control characters into their backslash equivalents but there seems to be a problem with the form feed character (hex 0C)

Below example pipes a string of 3 characters to hexdump: backspace (x08) newline (x0a) and form feed (x0c)

Hexdump's "%_u" format translates this string correctly to bs lf and ff
However the "%_c" format translates it to \b \n and \b
And that's wrong. The backslash escape sequence of form feed is \f and not \b
My BusyBox version v1.21.0. may be too old. Has this been corrected? Does this bug exist in the full version (which I don't have)?

Code: Select all

#!/bin/bash
echo -en "\x08\x0A\x0C" | hexdump  -e '1 "%_u\n"'
echo
echo -en "\x08\x0A\x0C" | hexdump  -e '1 "%_c\n"'
In fatdog64 both hexdump are present, busybox version is different from your's though.

Code: Select all

# whereis hexdump
hexdump: /usr/bin/hexdump /bin/hexdump /usr/share/man/man1/hexdump.1
#
# /usr/bin/hexdump -V
hexdump from util-linux 2.25.2
#
# /bin/hexdump --help
BusyBox v1.27.0.git (2017-11-10 04:22:11 UTC) multi-call binary.

Usage: hexdump [-bcCdefnosvxR] [FILE]...

Display FILEs (or stdin) in a user specified format

	-b		1-byte octal display
	-c		1-byte character display
	-d		2-byte decimal display
	-o		2-byte octal display
	-x		2-byte hex display
	-C		hex+ASCII 16 bytes per line
	-v		Show all (no dup folding)
	-e FORMAT_STR	Example: '16/1 "%02x|""\n"'
	-f FORMAT_FILE
	-n LENGTH	Show only first LENGTH bytes
	-s OFFSET	Skip OFFSET bytes
	-R		Reverse of 'hexdump -Cv'
# 
So I ran your code with both hexdumps.

hexdump from util-linux 2.25.2 gives following results

Code: Select all

# echo -en "\x08\x0A\x0C" | /usr/bin/hexdump  -e '1 "%_u\n"' 
bs
lf
ff
# echo -en "\x08\x0A\x0C" | /usr/bin/hexdump  -e '1 "%_c\n"'
\b
\n
\f
#
hexdump from BusyBox v1.27.0 gives same output

Code: Select all

# echo -en "\x08\x0A\x0C" | /bin/hexdump  -e '1 "%_u\n"' 
bs
lf
ff
# echo -en "\x08\x0A\x0C" | /bin/hexdump  -e '1 "%_c\n"'
\b
\n
\f
#
Hope this helps.

User avatar
MochiMoppel
Posts: 2084
Joined: Wed 26 Jan 2011, 09:06
Location: Japan

#5 Post by MochiMoppel »

Thanks everyone.

So versions 1.26.0 and newer seem to be OK.
https://busybox.net wrote:hexdump: fix numerous bugs in handling of backslashes
Wait a second - numerous? What did I miss? :lol:

Post Reply