Bug 5282 - Result of variable substitution in right hand side of I/O redirection causes trailing garbage byte
Summary: Result of variable substitution in right hand side of I/O redirection causes ...
Status: RESOLVED FIXED
Alias: None
Product: Busybox
Classification: Unclassified
Component: Standard Compliance (show other bugs)
Version: 1.19.x
Hardware: Other Linux
: P5 normal
Target Milestone: ---
Assignee: unassigned
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2012-06-06 17:17 UTC by Jo-Philipp Wich
Modified: 2012-06-09 00:10 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Jo-Philipp Wich 2012-06-06 17:17:48 UTC
When using the result of a variable substitution is used on the right hand side of a I/O redirection, the destination file name has a trialing garbage byte appended.

Consider the following testcase:

root@uplink:~# /bin/sh


BusyBox v1.19.4 (2012-05-27 23:56:19 CEST) built-in shell (ash)
Enter 'help' for a list of built-in commands.

# make sure there is no file already
root@uplink:~# rm -f /tmp/tmp1*

# test the substitutions with echo - working fine
root@uplink:~# x="tmp1:tmp2"; echo "${x#*:}" "/tmp/${x%:*}"
tmp2 /tmp/tmp1

# now trying to echo word #1 into word #2
root@uplink:~# x="tmp1:tmp2"; echo "${x#*:}" > "/tmp/${x%:*}"

# manually typing the expected destination:
root@uplink:~# cat /tmp/tmp1
cat: can't open '/tmp/tmp1': No such file or directory

# using arrow up and tab expansion my gnome terminal shows a trailing \210 byte:
root@uplink:~# cat /tmp/tmp1\210
tmp2

# using file globbing and hexdump confirms the bad path
root@uplink:~# echo -n /tmp/tmp1* | hexdump -C
00000000  2f 74 6d 70 2f 74 6d 70  31 88                    |/tmp/tmp1.|
0000000a


I have not digged into the relevant code so I can not yet suggest a more specific direction to look into.
Comment 1 Denys Vlasenko 2012-06-09 00:10:14 UTC
Fixed in git:

commit f451b2cfe042e3029b73261758b9ab7e956eaa03
Author: Denys Vlasenko <vda.linux@googlemail.com>
Date:   Sat Jun 9 02:06:57 2012 +0200

    ash: fix a bug in >${varexp} handling


Also available here:

http://busybox.net/downloads/fixes-1.20.1/busybox-1.20.1-ash.patch