Commit b82f723
committed
Fix IFS field splitting bugs in read -d ''
@dicktyr reports:
> for the following script
>
> IFS=$'\n' read -d '' v1 v2 <<< "$(printf 'a\nb')" ; \
> printf '[%s]\n' "$v1" "$v2"
>
> bash produces the expected output
>
> [a]
> [b]
>
> but ksh (93u+m/1.0.10) produces
>
> [a
> b
> ]
> []
The bug is that 'read' does not correctly do IFS splitting by
newline when given a null delimeter (-d '') or any delimiter other
than a newline.
In the course of debugging this, it was also found that there is
incorrect behavour when IFS is unset.
src/cmd/ksh93/bltins/read.c: sh_readline():
- If IFS is unset (ifs==NULL), handle field splitting using the
default value, $' \t\n' (e_sptbnl). This is specified by POSIX.
The type of ifs is changed to const char* to avoid a warning;
this is a good idea anyway since sh_readline should never change
the value of IFS.
- Backport a fix from ksh 93v- 2013-04-02: if the delimiter is not
newline but IFS contains a newline, turn on S_DELIM handling for
the newline in sh.ifstable. This gets us most of the way towards
a full fix, but leaves trailing newline delimiters intact, which
is incorrect.
- To fix that remaining problem, when stripping off trailing space
delimiters, don't only look for the S_SPACE state but also for
the S_DELIM state for isspace(3) characters. This *should* only
ever be relevant for newline characters but I'm preferring a more
generalised whitespace fix here, just in case.
src/cmd/ksh93/tests/builtins.sh:
- Remove an incorrect text that was enforcing the current buggy
behaviour. It was backported from ksh 93v- 2013-03-18, but we
didn't notice at the time that this test had been removed again
in ksh 93v- 2013-04-02. (re: cfc8744)
- Add tests for 10 reproducers related to this bug.
Resolves: #9261 parent 0f6866b commit b82f723
File tree
5 files changed
+57
-20
lines changed- src/cmd/ksh93
- bltins
- include
- tests
5 files changed
+57
-20
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3 | 3 | | |
4 | 4 | | |
5 | 5 | | |
6 | | - | |
| 6 | + | |
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
5 | 10 | | |
6 | 11 | | |
7 | 12 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
5 | | - | |
| 5 | + | |
6 | 6 | | |
7 | 7 | | |
8 | 8 | | |
| |||
221 | 221 | | |
222 | 222 | | |
223 | 223 | | |
224 | | - | |
| 224 | + | |
225 | 225 | | |
226 | 226 | | |
227 | 227 | | |
| |||
314 | 314 | | |
315 | 315 | | |
316 | 316 | | |
| 317 | + | |
| 318 | + | |
317 | 319 | | |
318 | 320 | | |
319 | 321 | | |
| |||
322 | 324 | | |
323 | 325 | | |
324 | 326 | | |
325 | | - | |
| 327 | + | |
| 328 | + | |
| 329 | + | |
| 330 | + | |
326 | 331 | | |
327 | 332 | | |
328 | 333 | | |
| |||
782 | 787 | | |
783 | 788 | | |
784 | 789 | | |
785 | | - | |
| 790 | + | |
786 | 791 | | |
787 | 792 | | |
788 | 793 | | |
789 | 794 | | |
790 | 795 | | |
791 | | - | |
| 796 | + | |
792 | 797 | | |
793 | 798 | | |
794 | 799 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
5 | | - | |
| 5 | + | |
6 | 6 | | |
7 | 7 | | |
8 | 8 | | |
| |||
18 | 18 | | |
19 | 19 | | |
20 | 20 | | |
21 | | - | |
| 21 | + | |
22 | 22 | | |
23 | 23 | | |
24 | 24 | | |
25 | 25 | | |
26 | 26 | | |
27 | 27 | | |
28 | | - | |
| 28 | + | |
29 | 29 | | |
30 | 30 | | |
31 | 31 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
5 | | - | |
| 5 | + | |
6 | 6 | | |
7 | 7 | | |
8 | 8 | | |
| |||
1576 | 1576 | | |
1577 | 1577 | | |
1578 | 1578 | | |
1579 | | - | |
1580 | | - | |
1581 | | - | |
1582 | | - | |
1583 | | - | |
1584 | | - | |
1585 | | - | |
1586 | | - | |
1587 | | - | |
1588 | | - | |
1589 | 1579 | | |
1590 | 1580 | | |
1591 | 1581 | | |
| |||
1756 | 1746 | | |
1757 | 1747 | | |
1758 | 1748 | | |
| 1749 | + | |
| 1750 | + | |
| 1751 | + | |
| 1752 | + | |
| 1753 | + | |
| 1754 | + | |
| 1755 | + | |
| 1756 | + | |
| 1757 | + | |
| 1758 | + | |
| 1759 | + | |
| 1760 | + | |
| 1761 | + | |
| 1762 | + | |
| 1763 | + | |
| 1764 | + | |
| 1765 | + | |
| 1766 | + | |
| 1767 | + | |
| 1768 | + | |
| 1769 | + | |
| 1770 | + | |
| 1771 | + | |
| 1772 | + | |
| 1773 | + | |
| 1774 | + | |
| 1775 | + | |
| 1776 | + | |
| 1777 | + | |
| 1778 | + | |
| 1779 | + | |
| 1780 | + | |
| 1781 | + | |
| 1782 | + | |
| 1783 | + | |
| 1784 | + | |
| 1785 | + | |
1759 | 1786 | | |
1760 | 1787 | | |
1761 | 1788 | | |
| |||
0 commit comments