Re: [PATCH] dash: Fix stack overflow from infinite recursion in script

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Op 18-07-19 om 20:27 schreef Jason Bowen:
A recursion limit is not without precedent. CPython sets a platform-
dependent recursion limit for this same purpose:

https://docs.python.org/3/library/sys.html#sys.setrecursionlimit

But indeed, the limit is "artificial" or arbitrary. It should just be
"enough" that it isn't hit often with typical use.

The arbitrariness of a hard-coded limit is indeed a problem. OK, crashing with a segfault is ugly because it makes the user suspect the shell is buggy, not the script. On the other hand, with a 'reasonable' limit, a script might still segfault on very small systems, while that limit disallows full use of system resources on large systems.

Regarding precedent: as far as I know, among POSIXy shells, a recursion limit is currently only implemented in zsh, with a user-settable FUNCNEST variable.

If such a feature were to be implemented, I think a configurable limit is preferable to a hard-coded limit, and IMHO zsh's precedent should be followed (including the name of the variable).

$ zsh -c 'f() { f; }; f'
f: maximum nested function level reached; increase FUNCNEST?

Of course, if you set FUNCNEST to a very large value, the stack will still overflow.

$ zsh -c 'FUNCNEST=999999999999999999; f() { f; }; f'
Segmentation fault: 11

Thanks,

- M.

--
modernish -- harness the shell
https://github.com/modernish/modernish



[Index of Archives]     [LARTC]     [Bugtraq]     [Yosemite Forum]     [Photo]

  Powered by Linux