regression re. fd redirections in COMSUB with TIF

Bug #907224 reported by Thorsten Glaser
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
mksh
Fix Released
Undecided
Unassigned

Bug Description

Original code found in /bin/zgrep on Debian Lenny.

tglase@tglase:~ $ cat reduced-testcase
exec 3>&1
echo = start one
captured=$(
        exec 5>&1
        (echo one-u; echo 0 >&5) | { tr u x; } >&3
)
echo "= captured<$captured>"

echo

echo = start two
captured=$(
        exec 5>&1
        (echo two-u; echo 0 >&5) | if :; then tr u x; fi >&3
)
echo "= captured<$captured>"
tglase@tglase:~ $ posh reduced-testcase
= start one
one-x
= captured<0>

= start two
two-x
= captured<0>
tglase@tglase:~ $ mksh reduced-testcase
= start one
one-x
= captured<0>

= start two
= captured<0
two-x>
tglase@tglase:~ $ mksh -o sh reduced-testcase
= start one
one-x
= captured<0>

= start two
= captured<0
two-x>
tglase@tglase:~ $ mksh -o posix reduced-testcase
= start one
one-x
= captured<0>

= start two
= captured<0
two-x>

Tracking down the changes:

tg@blau:~ $ mksh-R39c reduced-testcase
= start one
one-x
= captured<0>

= start two
two-x
= captured<0>
tg@blau:~ $ mksh-R40 reduced-testcase
= start one
one-x
= captured<0>

= start two
= captured<0
two-x>

This may or may not be related to the COMSUB rewrite.

Oh well, actually it is:

1|tg@blau:~ $ mksh-R39c tf
one() {
    exec 3>&1
    captured=$(^J^I^Iexec 5>&1^J^I^I(echo one-u; echo 0 >&5) | { tr u x; } >&3^J^I)
}
two() {
    exec 3>&1
    captured=$(^J^I^Iexec 5>&1^J^I^I(echo two-u; echo 0 >&5) | if :; then tr u x; fi >&3^J^I)
}
tg@blau:~ $ mksh-R40 tf
one() {
        exec 3>&1
        captured=$(exec 5>&1 ; ( echo one-u ; echo 0 >&5 ) | { tr u x ; } >&3 )
}
two() {
        exec 3>&1
        captured=$(exec 5>&1 ; ( echo two-u ; echo 0 >&5 ) | if : ; then tr u x ; fi )
}

This definitively needs tree-dump investigation.

Further reduced:

tg@blau:~ $ mksh-R39c -c 'exec 3>&1; x=$(echo 1; if :; then echo 3; echo >&2 2; fi >&3); echo "<$x>"'
3
2
<1>
tg@blau:~ $ mksh-R40 -c 'exec 3>&1; x=$(echo 1; if :; then echo 3; echo >&2 2; fi >&3); echo "<$x>"'
2
<1
3>

Revision history for this message
Thorsten Glaser (mirabilos) wrote :

Committed revision 1004EFCF98C06684CE3.

Changed in mksh:
status: New → Fix Committed
Revision history for this message
Thorsten Glaser (mirabilos) wrote :

fixed in R40e and HEAD

Changed in mksh:
status: Fix Committed → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.