Commit a9283be
Fix annoying silent crash in builtins.sh under ASan (#810)
Under ASan the builtins.sh script silently exits with exit status 1
and no backtrace. After isolating the bug into a simplified script,
I managed to reproduce it with an actual stacktrace. Reproducer:
set -o xtrace # Shows how far the script goes before crashing
# (which is inconsistent and system-dependent
# AFAICT; ALL_LIBCMD can affect it).
bltin='/opt/ast/bin/basename
/opt/ast/bin/cat
/opt/ast/bin/cp
/opt/ast/bin/cut
/opt/ast/bin/dirname
/opt/ast/bin/getconf
/opt/ast/bin/ln
/opt/ast/bin/mktemp
/opt/ast/bin/mv' # Feel free to expand this with other commands
# from libcmd if you with.
for i in ${bltin}
do ({ PATH=/opt/ast/bin; "${bltin##*/}" --this-option-does-not-exist; } 2>&1)
done
Stacktrace obtained after much effort:
=================================================================
==116622==ERROR: AddressSanitizer: heap-use-after-free on address 0x502000000e50 at pc 0x72ad1bb52b7f bp 0x7ffc8b5a0cd0 sp 0x7ffc8b5a0478
READ of size 3 at 0x502000000e50 thread T0
#0 0x72ad1bb52b7e in memcpy /usr/src/debug/gcc/gcc/libsanitizer/sanitizer_common/sanitizer_common_interceptors_memintrinsics.inc:115
#1 0x5bb0a922f3de in synthesize /home/johno/GitRepos/KornShell/ksh/src/lib/libast/port/astconf.c:466
#2 0x5bb0a92305cd in initialize /home/johno/GitRepos/KornShell/ksh/src/lib/libast/port/astconf.c:591
#3 0x5bb0a9230fac in format /home/johno/GitRepos/KornShell/ksh/src/lib/libast/port/astconf.c:632
#4 0x5bb0a923ba4b in astgetconf /home/johno/GitRepos/KornShell/ksh/src/lib/libast/port/astconf.c:1382
#5 0x5bb0a923d5c5 in astconf /home/johno/GitRepos/KornShell/ksh/src/lib/libast/port/astconf.c:1472
#6 0x5bb0a924e07b in initconformance /home/johno/GitRepos/KornShell/ksh/src/lib/libast/misc/conformance.c:50
#7 0x5bb0a924eff2 in conformance /home/johno/GitRepos/KornShell/ksh/src/lib/libast/misc/conformance.c:122
#8 0x5bb0a9288b8e in b_cp /home/johno/GitRepos/KornShell/ksh/src/lib/libcmd/cp.c:706
<CUT>
src/lib/libast/port/astconf.c:
- Remove realloc (newof) shenanigans such that memcpy can always be
used.
- Produce an obvious panic if memory allocation fails.
- Use conferror mechanism to post errors when memory cannot be
allocated (also applied to code that ought have already had such
error handling).
src/cmd/ksh93/sh/init.c:
- For correctness, prevent memory leaks by freeing memory in
sh_realloc upon failure.
Co-authored-by: Martijn Dekker <martijn@inlv.org>1 parent f98ed55 commit a9283be
3 files changed
+45
-21
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
7 | 10 | | |
8 | 11 | | |
9 | 12 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
242 | 242 | | |
243 | 243 | | |
244 | 244 | | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
245 | 248 | | |
| 249 | + | |
246 | 250 | | |
247 | 251 | | |
248 | 252 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
70 | 70 | | |
71 | 71 | | |
72 | 72 | | |
73 | | - | |
| 73 | + | |
74 | 74 | | |
75 | 75 | | |
76 | 76 | | |
| |||
300 | 300 | | |
301 | 301 | | |
302 | 302 | | |
303 | | - | |
| 303 | + | |
304 | 304 | | |
305 | 305 | | |
306 | 306 | | |
307 | 307 | | |
308 | 308 | | |
| 309 | + | |
309 | 310 | | |
310 | 311 | | |
311 | 312 | | |
| |||
326 | 327 | | |
327 | 328 | | |
328 | 329 | | |
| 330 | + | |
| 331 | + | |
| 332 | + | |
329 | 333 | | |
| 334 | + | |
330 | 335 | | |
331 | 336 | | |
332 | 337 | | |
| |||
434 | 439 | | |
435 | 440 | | |
436 | 441 | | |
| 442 | + | |
| 443 | + | |
| 444 | + | |
437 | 445 | | |
| 446 | + | |
438 | 447 | | |
439 | 448 | | |
440 | 449 | | |
| |||
458 | 467 | | |
459 | 468 | | |
460 | 469 | | |
461 | | - | |
462 | | - | |
463 | | - | |
| 470 | + | |
464 | 471 | | |
465 | | - | |
466 | | - | |
467 | | - | |
| 472 | + | |
| 473 | + | |
| 474 | + | |
| 475 | + | |
| 476 | + | |
| 477 | + | |
468 | 478 | | |
469 | | - | |
| 479 | + | |
| 480 | + | |
| 481 | + | |
| 482 | + | |
| 483 | + | |
| 484 | + | |
| 485 | + | |
470 | 486 | | |
471 | 487 | | |
472 | 488 | | |
| |||
477 | 493 | | |
478 | 494 | | |
479 | 495 | | |
480 | | - | |
| 496 | + | |
481 | 497 | | |
482 | 498 | | |
483 | 499 | | |
| |||
588 | 604 | | |
589 | 605 | | |
590 | 606 | | |
591 | | - | |
| 607 | + | |
592 | 608 | | |
593 | 609 | | |
594 | 610 | | |
| |||
602 | 618 | | |
603 | 619 | | |
604 | 620 | | |
605 | | - | |
606 | | - | |
607 | | - | |
608 | 621 | | |
609 | 622 | | |
610 | 623 | | |
| |||
633 | 646 | | |
634 | 647 | | |
635 | 648 | | |
636 | | - | |
637 | | - | |
| 649 | + | |
| 650 | + | |
638 | 651 | | |
639 | 652 | | |
640 | 653 | | |
| |||
660 | 673 | | |
661 | 674 | | |
662 | 675 | | |
663 | | - | |
664 | | - | |
| 676 | + | |
| 677 | + | |
665 | 678 | | |
666 | 679 | | |
667 | 680 | | |
| |||
703 | 716 | | |
704 | 717 | | |
705 | 718 | | |
| 719 | + | |
| 720 | + | |
| 721 | + | |
706 | 722 | | |
| 723 | + | |
707 | 724 | | |
708 | 725 | | |
709 | 726 | | |
| |||
712 | 729 | | |
713 | 730 | | |
714 | 731 | | |
715 | | - | |
| 732 | + | |
716 | 733 | | |
717 | 734 | | |
718 | | - | |
| 735 | + | |
719 | 736 | | |
720 | 737 | | |
721 | 738 | | |
| |||
724 | 741 | | |
725 | 742 | | |
726 | 743 | | |
727 | | - | |
| 744 | + | |
728 | 745 | | |
729 | 746 | | |
730 | 747 | | |
| |||
0 commit comments