From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 14180 invoked by alias); 26 Feb 2017 06:05:49 -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: 40645 Received: (qmail 16271 invoked from network); 26 Feb 2017 06:05:49 -0000 X-Qmail-Scanner-Diagnostics: from kahlil.inlv.org 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(37.59.109.123):SA:0(-0.0/5.0):. Processed in 0.866881 secs); 26 Feb 2017 06:05:49 -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=-0.0 required=5.0 tests=RP_MATCHES_RCVD autolearn=unavailable autolearn_force=no version=3.4.1 X-Envelope-From: martijn@inlv.org X-Qmail-Scanner-Mime-Attachments: | X-Qmail-Scanner-Zip-Files: | Received-SPF: none (ns1.primenet.com.au: domain at inlv.org does not designate permitted sender hosts) From: Martijn Dekker To: Zsh hackers list Subject: [BUG] Solaris-specific program flow corruption after subshell error exit Message-ID: <5258197e-1903-b188-f033-fc424a271077@inlv.org> Date: Sun, 26 Feb 2017 06:36:55 +0100 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.11; rv:45.0) Gecko/20100101 Thunderbird/45.7.1 MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit Modernish (cross-platform POSIX shell library with ambitions to become modernizr/jQuery for the shell) is finally getting near a first testing release, so I'm doing testing on all shell/OS combinations I can get my hands on. In the course of that testing I've come across a zsh bug that *only* manifests on Solaris, at least version 11.3. (A free VirtualBox VM for evaluation purposes is available from Oracle.) If a subshell exits due to an error in a special builtin or redirection, execution flow is corrupted in such a manner that, when end of file is reached without an explicit 'return' or 'exit' being encountered, execution of the file does not end but restarts at the point exactly after the subshell was exited. The second time around, if program specifics allow it, execution ends normally. The bug only manifests if POSIXBUILTINS is active, and only on Solaris. I confirmed the bug on zsh 5.0.7 (as shipped by default), zsh 5.2 (package available from Oracle), *and* today's current git version (compiled myself, obviously). So it appears to be long-standing. Test script: # Bug only occurs with POSIXBUILTINS active. setopt POSIXBUILTINS # Execution counter. count=0 # Exiting from a subshell due to an error triggers the bug. (set -o nonexistent_@_option) 2>/dev/null # With the bug, this will be executed twice so 'let' returns true. let "(count += 1) > 1" && echo "BUG DETECTED" # EOF. To trigger the bug, don't explicitly exit or return. Save and run with "zsh test.zsh". On Solaris, it outputs "BUG DETECTED". On any other OS, it outputs nothing. Interestingly, a sourced dot script will trigger the bug just as cleanly as a standalone script, so it is possible to test for the bug from another program without affecting that program. Actually, things get *really* interesting if you add "return" to the end of the test script and source it from another script as a dot script. In that case, the bug appears to "move up" in the calling hierarchy; that is, if the file sourcing this test script (with the extra "return") ends execution due to end of file (i.e. no "return" or "exit"), its execution resumes to just after the command that sourced this file. (This is how I initially encountered the bug: when I tried 'modernish --test', zsh 5.0.7 on Solaris would mysteriously try to run the test suite twice. Which was "interesting" to track down, to say the least.) Good luck with this one. Let me know if you need me to do anything specific to help track it down. - M.