tcsh-org / tcsh

This is a read-only mirror of the tcsh code repository.
https://www.tcsh.org/
Other
232 stars 42 forks source link

tcsh crashes when `$status` is read-only #39

Closed GabrielRavier closed 3 years ago

GabrielRavier commented 3 years ago

MCVE:

$ tcsh -fc 'set -r status;:'
set: $status is read-only.
set: $status is read-only.
set: $status is read-only.
set: $status is read-only.
set: $status is read-only.
set: $status is read-only.
set: $status is read-only.
[after a veeeeeery loooong while of this repeated stream of read-only errors]
set: $status is read-only.
set: $status is read-only.
set: $status is read-only.
set: $status is read-only.
set: $status is read-only.
set: $status is read-only.
set: $status is read-only.
Segmentation fault (core dumped)

Tested it on master and can confirm it still occurs there.

It seems likely to me that this is what's happening:

  1. tcsh uses $status for the purposes of holding the last command return status.
  2. set -r status sets $status to be read-only, meaning any attempts to write to it result in an error
  3. tcsh tries to set $status to the result of the command at some point, I don't really know exactly what triggers it but "finishing" a part of syntax that gives a status and having something after it seems to be what's triggering it for me (as not having the ;: part doesn't crash it)
  4. this results in an error since $status is read-only
  5. the error recovery routine attempts to "end" the command
  6. it goes back to step 2 and dies in a stack overflow due to the infinite recursive loop
zoulasc commented 3 years ago

Fixed, thanks!