Puppy Linux Discussion Forum Forum Index Puppy Linux Discussion Forum
Puppy HOME page : puppylinux.com
"THE" alternative forum : puppylinux.info
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

The time now is Sat 18 Aug 2018, 21:28
All times are UTC - 4
 Forum index » Off-Topic Area » Programming
Busybox hexdump bug
Post new topic   Reply to topic View previous topic :: View next topic
Page 1 of 1 [5 Posts]  
Author Message
MochiMoppel


Joined: 26 Jan 2011
Posts: 1579
Location: Japan

PostPosted: Thu 10 May 2018, 08:59    Post subject:  Busybox hexdump bug  

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:
#!/bin/bash
echo -en "\x08\x0A\x0C" | hexdump  -e '1 "%_u\n"'
echo
echo -en "\x08\x0A\x0C" | hexdump  -e '1 "%_c\n"'
Back to top
View user's profile Send private message 
fredx181


Joined: 11 Dec 2013
Posts: 3219
Location: holland

PostPosted: Thu 10 May 2018, 12:25    Post subject:  

Hi mochimoppel, on Ubuntu Bionic, busybox version 1.27.2, it is correct:
Code:
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

_________________
Dog Linux website
Back to top
View user's profile Send private message 
misko_2083


Joined: 08 Nov 2016
Posts: 53

PostPosted: Thu 10 May 2018, 18:17    Post subject: Re: Busybox hexdump bug  

busybox 1.22.1 busybox hexdump: b

Code:
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:
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
Back to top
View user's profile Send private message 
drunkjedi


Joined: 24 May 2015
Posts: 897

PostPosted: Fri 11 May 2018, 00:55    Post subject: Re: Busybox hexdump bug  

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:
#!/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:
# 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:
# 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:
# 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.
Back to top
View user's profile Send private message 
MochiMoppel


Joined: 26 Jan 2011
Posts: 1579
Location: Japan

PostPosted: Sat 12 May 2018, 22:06    Post subject:  

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? Laughing
Back to top
View user's profile Send private message 
Display posts from previous:   Sort by:   
Page 1 of 1 [5 Posts]  
Post new topic   Reply to topic View previous topic :: View next topic
 Forum index » Off-Topic Area » Programming
Jump to:  

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group
[ Time: 0.0586s ][ Queries: 13 (0.0249s) ][ GZIP on ]