Repository navigation
Commit 0af2293
committed
Reproducer (requires interactive shell):
$ function fn { cat < this is
> a test
> EOF
> }
$ fn
this is
a test
$ sleep 3
^C
$ fn
(no output)
All here-documents in functions that have been loaded are lost when
the user interrupts any command on the interactive shell, or when
any other condition occurs that causes the shell to abort and
return to the prompt (i.e., the SH_JMPERREXIT jmpval condition).
The bug was caused by the Solaris patch in the referenced commit,
which closes and resets `sh.heredocs`, the Sfio stream that keeps
loaded here-docs, including those in memory-resident functions.
Each here-doc becomes part of the stream and its offset and size is
kept track of. So, calling sfclose() on that is clearly incorrect.
The patch was meant to fix this bug (and did fix it):
att#1472
In that bug, ksh crashed badly if the user interrupted the entry of
a here-doc on the interactive command line, and then a command
substitution was executed as part of the PS1 prompt. The issue was
that, due to the interrupt, the 'heredoc' member of the Lex_t lexer
state struct was never reset properly before the next prompt was
expanded/printed, causing the command substitution to be wrongly
treated as a here-doc. So, resetting lp->heredoc is the only
correct and necessary part of commit cf53abb.
However, in ksh 93u+m, this has been made unnecessary by the
combination of commits dfb699b, which resets the lexer state
before expanding and showing each PS1 prompt, and 2e000c9, which
fixes sh_lexopen() to reset all of the lexer struct except $LINENO-
related items, which fixed it to reset lp->heredoc as well.
So, the referenced commit is not only broken but (as of 2e000c9)
also obsolete, and is now reverted.
The full discussion and proof of correctness of this fix is too
elaborate for a commit message, but can be found at:
#978 (comment)
Resolves: #978
1 parent e1a5673 commit 0af2293
4 files changed
Lines changed: 24 additions & 15 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
5 | 11 | | |
6 | 12 | | |
7 | 13 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
21 | 21 | | |
22 | 22 | | |
23 | 23 | | |
24 | | - | |
| 24 | + | |
25 | 25 | | |
26 | 26 | | |
27 | 27 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
428 | 428 | | |
429 | 429 | | |
430 | 430 | | |
431 | | - | |
432 | | - | |
433 | | - | |
434 | | - | |
435 | | - | |
436 | | - | |
437 | | - | |
438 | | - | |
439 | | - | |
440 | | - | |
441 | | - | |
442 | | - | |
443 | | - | |
444 | | - | |
445 | 431 | | |
446 | 432 | | |
447 | 433 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1413 | 1413 | | |
1414 | 1414 | | |
1415 | 1415 | | |
| 1416 | + | |
| 1417 | + | |
| 1418 | + | |
| 1419 | + | |
| 1420 | + | |
| 1421 | + | |
| 1422 | + | |
| 1423 | + | |
| 1424 | + | |
| 1425 | + | |
| 1426 | + | |
| 1427 | + | |
| 1428 | + | |
| 1429 | + | |
| 1430 | + | |
| 1431 | + | |
| 1432 | + | |
1416 | 1433 | | |
1417 | 1434 | | |
0 commit comments