2

I just noticed that the bash I'm using (4.2.25(1)) isn't protected against infinite function recursion. In such a case a Segfault happens (and the bash process terminates). To check this on your bash, just type:

$ bash
$ f() { f; }
$ f

(Starting a subshell first (the first line) gives us a candidate we can experiment with without endangering the shell of the terminal; without the first line, your terminal window will probably close so quickly you cannot see anything interesting.)

I understand the reason of this phenomenon, I think; it probably is a stack overflow which results in the bash trying to write into regions of the memory which are not assigned to its process.

What I'm wondering about is two things:

  • Shouldn't there be a check in the bash to protect it against such situations? A more decent error message like "Stack Overflow in shell function" would certainly be better than a simple unhelpful Segfault.

  • Could this be a security issue? Before this method writes into memory parts which are not assigned to the process (resulting in a Segfault), it might overwrite other parts which were not meant to be used for the bash-internal stack.

Alfe
  • 283
  • 3
  • 17

0 Answers0