Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: unbounded recursive call in a shell script crashes zsh
- X-seq: zsh-workers 40985
- From: Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx>
- To: zsh-workers@xxxxxxx
- Subject: Re: unbounded recursive call in a shell script crashes zsh
- Date: Sun, 16 Apr 2017 17:17:33 -0700
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=brasslantern-com.20150623.gappssmtp.com; s=20150623; h=from:message-id:date:in-reply-to:comments:references:to:subject :mime-version; bh=siL50iEec57Mpwy3FA+GCmVZqY8jyd+/12soOKtIsIE=; b=cxkD+/rEtzsInzQOtY9X+zjtQp4DJfCgT6iz72NLcIhz7Nynk9GkRlwQoAAxTFT7Gm Vbl3Us/5ddLa+DI/r/F4osyGkiFtZJqZpRW9kiqYX2Twxhs1S4SjQINAlmYaD/cZTYTk kuYy8c/JI9XZ1SEoU7fMgbV6xbD5i8g4WdRniV+dRI5z8Gk6/kOq8bcamAkEmM56Zusp 8jm7o0Z285fz/yvjBRoCtt93UIqSlfKgx5iHowW9n++/hIa/Nca232WRJKqoxc+Lw3Uo EyKlZhYtiL40iwHxLHYCrf5MO7qHn8+S8yKGFYgafhmWm5DvbAO14kcJOqad/ULVjGDp W8rQ==
- In-reply-to: <20170416231218.GA28022@fujitsu.shahaf.local2>
- List-help: <mailto:zsh-workers-help@zsh.org>
- List-id: Zsh Workers List <zsh-workers.zsh.org>
- List-post: <mailto:zsh-workers@zsh.org>
- Mailing-list: contact zsh-workers-help@xxxxxxx; run by ezmlm
- References: <2960832.nVDpiBkaWZ@kdudka-nb> <2420758.31stuSQeAV@kdudka-nb> <CAH+w=7atHK+_7fdzxCB4gRkWiKW8zCcTvW-qHM-0fUjH=OsPDQ@mail.gmail.com> <2350280.olGvC23INb@kdudka-nb> <CAFOazAO2jcj+zPpJuHXtykUE4yGR0FnYA5+-xHgH4nu_gDZgbw@mail.gmail.com> <CAFOazAM8N5ZQEv_HtQwt-18M6aNOTEMhGAmYxO0De1cjpjnjXA@mail.gmail.com> <170415091456.ZM22606@torch.brasslantern.com> <20170416185628.GA25858@fujitsu.shahaf.local2> <170416140016.ZM21368@torch.brasslantern.com> <20170416231218.GA28022@fujitsu.shahaf.local2>
On Apr 16, 11:12pm, Daniel Shahaf wrote:
}
} I realized that the code could compare how far it is from main() to
} RLIMIT_STACK and bail out gracefully if it has, say, less than X KB or
} Y% of stack remaining.
Well ...
Another approach would be to add a C function that does nothing more
than declare a large array to force a stack allocation, and assign
something to the last byte; then in doshfunc(), trap the appropriate
signals (SIGSEGV and SIGSTKFLT ?) while calling that function. If a
signal is raised, bail out as if MAX_FUNCTION_DEPTH has been reached.
I suspect this would destroy some efficiency gains Sebastian has been
so diligently wringing out of the code the last few months, but it'd
probably be fairly bulletpoof. doshfunc() could remember the depth it
last safely reached and skip calling the stack-probe until that was
next exceeded, so you'd only pay the penalty once.
But is all this really worth it?
I note in passing that MAX_FUNCTION_DEPTH can be switched off at compile
time, leaving the shell entirely at the mercy of ths script writer in
this regard.
Messages sorted by:
Reverse Date,
Date,
Thread,
Author