Commit dd1efb4
committed
pty: fix char overflow causing test failures (re: 8aef678)
As of the referenced commit, the pty.sh regression tests were
massively failing on some systems (at least Linux/s390 and
NetBSD/arm64) with failure message showing evidence of corrupted
values.
The problem was caused by the type of the 'restore' Match_t member
being changed from int to char, on the apparent assumption that
only values from char variables were to be stored in it. But that
is not the case; 'restore' is set to -1 to indicate that no
character is currently saved and none should be restored.
So the obvious fix would be to simply revert the type of 'restore'
back to int. However, I'm now seeing another, long-standing problem
in the code. The whole program works with char* pointers, not
unsigned char*. So on systems where char is signed, bytes with the
8th bit set (like UTF-8 characters) will produce negative values,
which gets stored in Match_t's 'restore' as negative, which means
restoring doesn't happen.
We could get around that by using unsigned char* instead of char*
everywhere, but that would be a large diff with lots of onerous
typecasts to silence compiler warnings[*] as unsigned char values
are passed to functions that expect char parameters. So, instead:
src/cmd/builtin/pty.c:
- Rename Match_t's 'restore' to 'save', keep char type. Only use it
for storing char values, which fixes the problem.
- Add 'saving' member, a flag indicating if the value in 'save'
should be restored. This replaces the -1 value of 'restore'.
- Adapt the code to use these, which is straightforward.
Thanks to @phidebian for the report.
Resolves: #962
[*] Those warnings don't normally show up, but do when compiling
with -Wsign-compare -Wshorten-64-to-32 -Wsign-conversion
-Wimplicit-int-conversion, as we now do as part of @JohnoKing's
project to make ksh ready to handle large amounts of data in a
64-bit address space.1 parent 7d0bddc commit dd1efb4
1 file changed
Lines changed: 21 additions & 18 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
511 | 511 | | |
512 | 512 | | |
513 | 513 | | |
514 | | - | |
| 514 | + | |
| 515 | + | |
515 | 516 | | |
516 | 517 | | |
517 | 518 | | |
| |||
537 | 538 | | |
538 | 539 | | |
539 | 540 | | |
540 | | - | |
541 | | - | |
| 541 | + | |
| 542 | + | |
542 | 543 | | |
543 | 544 | | |
544 | 545 | | |
545 | 546 | | |
546 | | - | |
| 547 | + | |
547 | 548 | | |
548 | 549 | | |
549 | 550 | | |
| |||
571 | 572 | | |
572 | 573 | | |
573 | 574 | | |
574 | | - | |
575 | | - | |
| 575 | + | |
| 576 | + | |
576 | 577 | | |
577 | | - | |
| 578 | + | |
| 579 | + | |
578 | 580 | | |
579 | 581 | | |
580 | 582 | | |
| |||
600 | 602 | | |
601 | 603 | | |
602 | 604 | | |
603 | | - | |
| 605 | + | |
604 | 606 | | |
605 | | - | |
606 | | - | |
| 607 | + | |
| 608 | + | |
607 | 609 | | |
608 | 610 | | |
609 | 611 | | |
| |||
631 | 633 | | |
632 | 634 | | |
633 | 635 | | |
634 | | - | |
| 636 | + | |
635 | 637 | | |
636 | | - | |
637 | | - | |
| 638 | + | |
| 639 | + | |
638 | 640 | | |
639 | 641 | | |
640 | 642 | | |
| |||
669 | 671 | | |
670 | 672 | | |
671 | 673 | | |
672 | | - | |
673 | | - | |
| 674 | + | |
| 675 | + | |
674 | 676 | | |
675 | 677 | | |
676 | | - | |
| 678 | + | |
| 679 | + | |
677 | 680 | | |
678 | 681 | | |
679 | 682 | | |
| |||
687 | 690 | | |
688 | 691 | | |
689 | 692 | | |
690 | | - | |
| 693 | + | |
691 | 694 | | |
692 | 695 | | |
693 | 696 | | |
| |||
803 | 806 | | |
804 | 807 | | |
805 | 808 | | |
806 | | - | |
| 809 | + | |
807 | 810 | | |
808 | 811 | | |
809 | 812 | | |
| |||
0 commit comments