From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 4162 invoked by alias); 17 Apr 2017 00:17:17 -0000 Mailing-List: contact zsh-workers-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Workers List List-Post: List-Help: X-Seq: 40985 Received: (qmail 3219 invoked from network); 17 Apr 2017 00:17:17 -0000 X-Qmail-Scanner-Diagnostics: from mail-ua0-f172.google.com by f.primenet.com.au (envelope-from , uid 7791) with qmail-scanner-2.11 (clamdscan: 0.99.2/21882. spamassassin: 3.4.1. Clear:RC:0(209.85.217.172):SA:0(-2.8/5.0):. Processed in 1.06489 secs); 17 Apr 2017 00:17:17 -0000 X-Spam-Checker-Version: SpamAssassin 3.4.1 (2015-04-28) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-2.8 required=5.0 tests=RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,SPF_PASS,T_DKIM_INVALID autolearn=unavailable autolearn_force=no version=3.4.1 X-Envelope-From: schaefer@brasslantern.com X-Qmail-Scanner-Mime-Attachments: | X-Qmail-Scanner-Zip-Files: | Received-SPF: pass (ns1.primenet.com.au: SPF record at _netblocks.google.com designates 209.85.217.172 as permitted sender) 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== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:message-id:date:in-reply-to:comments :references:to:subject:mime-version; bh=siL50iEec57Mpwy3FA+GCmVZqY8jyd+/12soOKtIsIE=; b=kuKH4UVkwIfM5H0js8hy33X9d/KBQNI1zsF6/Rlct+J6GCXjlM0E5FFsw1/ZZ4Lvcl L8Tzlph1w8t/DTi90Rrm91vtlZka43W6jnQX08GbPB4mTudMkeeQgjGofnKgnIN7OVkk hUFC2o5ERyKdjq5FurpaFu0Ba7oWOiGyRGwmdGciFvO3i7iI51NG/fESOhVc7HUfcOdO Im4kXflVsEsFJYVAy2VZo25fj/tc8FTNq1yBUvRfNNuiEemlPIoMgPdYbEjXRCXH5T8k qpbhuYdT1gR+GHPndgkaMUB8FOXibQibJQLXFTJq536wa4W2wXZVPixTTgwaim+v8lHq f19w== X-Gm-Message-State: AN3rC/4Cf8xWqWDcTkDRerJETsXlJC5dmfhKlY4V5gbiZKUTlGYsrr+X R69GD6h8UXZDaJmX X-Received: by 10.159.33.166 with SMTP id 35mr7166324uac.147.1492388229082; Sun, 16 Apr 2017 17:17:09 -0700 (PDT) From: Bart Schaefer Message-Id: <170416171733.ZM21913@torch.brasslantern.com> Date: Sun, 16 Apr 2017 17:17:33 -0700 In-Reply-To: <20170416231218.GA28022@fujitsu.shahaf.local2> Comments: In reply to Daniel Shahaf "Re: unbounded recursive call in a shell script crashes zsh" (Apr 16, 11:12pm) References: <2960832.nVDpiBkaWZ@kdudka-nb> <2420758.31stuSQeAV@kdudka-nb> <2350280.olGvC23INb@kdudka-nb> <170415091456.ZM22606@torch.brasslantern.com> <20170416185628.GA25858@fujitsu.shahaf.local2> <170416140016.ZM21368@torch.brasslantern.com> <20170416231218.GA28022@fujitsu.shahaf.local2> X-Mailer: OpenZMail Classic (0.9.2 24April2005) To: zsh-workers@zsh.org Subject: Re: unbounded recursive call in a shell script crashes zsh MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii 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.