x=<< functionality cannot be used in functions
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
mksh |
Fix Released
|
Medium
|
Thorsten Glaser |
Bug Description
Several bugs with this construct:
x=<<EOF
foo
EOF
x+=<<
foo
<<
1. It cannot be used in functions: assignment is done at parse time
2. It uses ATEMP of parse time, which is gone at runtime in functions
⇒ hides first bug unless exec.c alloc(z * 2 + n, ATEMP) → APERM
3. Size calculations not fully checked, one too big
⇒ (z-1) * 2 + 1 /* EOS */ + n
Ad 1:
(sid-amd64)
a
abla5424 bar
abla5424 bar bla5424 bar
function bar {
}
(sid-amd64)
function bar {
x+=<<
bla$RANDOM bar
<<
}
x=a
echo $x
bar
echo $x
bar
echo $x
typeset -f bar
Substitution happens at first use:
(sid-amd64)
function bar {
x=<<
bla$RANDOM bar
<<
}
function bar {
}
(sid-amd64)
function bar {
x=<<
bla$RANDOM bar
<<
}
function bar {
}
(sid-amd64)
function bar {
x=<<
bla$RANDOM bar
<<
}
typeset -f bar
bar
typeset -f bar
So this is even worse than thought, the ATEMP context is the one from the first use of the function…
This was introduced in R40, when the x=<< syntax was added.
Changed in mksh: | |
importance: | High → Medium |
Changed in mksh: | |
status: | Fix Committed → Fix Released |
This additionally requires a reparse hack (see lex.c for IONDELIM) because the tree.c printing code appends a trailing newline to all constructs unconditionally; we can remove that when the latter is no longer true (just documenting).