From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=-1.1 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE autolearn=ham autolearn_force=no version=3.4.2 Received: from primenet.com.au (ns1.primenet.com.au [203.24.36.2]) by inbox.vuxu.org (OpenSMTPD) with ESMTP id c8ea755d for ; Tue, 30 Jul 2019 22:34:19 +0000 (UTC) Received: (qmail 16364 invoked by alias); 30 Jul 2019 22:33:44 -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: List-Unsubscribe: X-Seq: 44616 Received: (qmail 21732 invoked by uid 1010); 30 Jul 2019 22:33:44 -0000 X-Qmail-Scanner-Diagnostics: from mail-io1-f43.google.com by f.primenet.com.au (envelope-from , uid 7791) with qmail-scanner-2.11 (clamdscan: 0.101.2/25524. spamassassin: 3.4.2. Clear:RC:0(209.85.166.43):SA:0(-2.0/5.0):. Processed in 0.834863 secs); 30 Jul 2019 22:33:44 -0000 X-Envelope-From: roman.perepelitsa@gmail.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.166.43 as permitted sender) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc:content-transfer-encoding; bh=1M6Jc1BJhD4GCmmptnyl1MPX22/8M4XANaOMAc6Eoc8=; b=lVNn/AslBHE9xpH+4RWEnMRtm2TZoXuvleEFsWNtf31LTR41/Z05VLq2nXtJ+OXJDC eKDzFxRht8gbQ8/3Z1a6kLmGJV+y+NVZ4x12eHNdsLt7zNoyDZGVhmeaGyFXe4oVp31k 8ZHJy6mWYnipm/vCm2a41AwGgJegFrW29JU0cv2xbUui0ts3vt0E+HTobCSYvRnMvOvu nhb8UWXpfk0XPocttzmE3deOGh6z3gL1YFcHK6/OgVy2PB153EFHA6MneUeWzTNyLKu/ wue7WXNPeG5RtH0pheb/5OlfRFSajOPXB1VEvnHVzMgIZB1Wl7m2QMyCH99steS8uheD 7g4A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc:content-transfer-encoding; bh=1M6Jc1BJhD4GCmmptnyl1MPX22/8M4XANaOMAc6Eoc8=; b=AyqB/hAmMKzdzWhnmSJKZPlgX2MjI8viAVzs+ZAGeJ2bdWbChCfG0Iv2mc7RFwtBzK UDQj0Qa/0TeD6NEktvfGxsv9OgR08VbAnAOk5jVRIhL4e7CA5IMXyDV/O1r/UD9yWHa+ vpVBc63eoCwXInOr07TBPMe6mTRxIJCdvptF2R99VSk80OT51usoEjvWJYr5bqsTH4Za lM41Y+DIO1NQwgHut9zSN0g6osojyO4ZumSh7LUAAkepdmFVhofa4rn6ba13gTlyzWoq 0VIni2GWkcoMRjYF5LgV+wXqhFaVIHaCSisJtggHNvk8jrjc0HySztHMXrFxPOLLmQup syBA== X-Gm-Message-State: APjAAAUVZss5Q1crZ7oKvEBygFiptQRfRlNb3pmSb1r63rxSzpCAyBZa BkJhU4IAT1LYe4axnG+xSAtdU3e3lwd9B9vjKND2+cU1cs4= X-Google-Smtp-Source: APXvYqw7PDdHJmAEEhd0WCh/2IMuc14z1FYfCq1wh4Yg7KjJ0K5QgrNbIJg2q8Zmn2gAipOXMpEOPe8FbNJxMmblrrI= X-Received: by 2002:a02:528a:: with SMTP id d132mr115365431jab.68.1564525991050; Tue, 30 Jul 2019 15:33:11 -0700 (PDT) MIME-Version: 1.0 References: <49013421-774e-4389-a25d-680f1d97a8ef@www.fastmail.com> In-Reply-To: <49013421-774e-4389-a25d-680f1d97a8ef@www.fastmail.com> From: Roman Perepelitsa Date: Wed, 31 Jul 2019 00:32:59 +0200 Message-ID: Subject: =?UTF-8?Q?Re=3A_A_serious_bug_in_execution_=E2=80=93_where_to_debug=3F?= To: Daniel Shahaf Cc: Zsh hackers list Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Wed, Jul 31, 2019 at 12:19 AM Daniel Shahaf wro= te: > > Roman Perepelitsa wrote on Tue, 30 Jul 2019 21:46 +00:00: > > You should call `emulate -L zsh` from every functions that can be > > called by any code other than yours. It's almost impossible to write > > code that works the same way with all combinations of options. In my > > public code I also unset aliases. These defensive measures reduce the > > number of bug reports by *a lot*. People really seem to like creating > > global aliases with single-letter names. > > z-sy-h also does 'emulate -L' and unsets aliases. By the way, why does it deal with aliases manually instead of `unsetopt aliases`? > I wonder if there > should be a built-in way to do this, in order to make it easier to write > plugins? Perhaps a =C2=ABsource -U foo.zsh=C2=BB syntax, as in autoload? The only problem I have with `unsetopt aliases` is that it has to be done before a function is parsed. This means using one of two patterns: 1. Remember at the top of the file if `aliases` options is set, then unset the option. At the bottom of the file, restore aliases. 2. Use two files. The first contains the real meet. The second has an anonymous function with `emulate -L zsh && unsetopt alizes && source first.zsh`. The first is bound to sometimes fail to restore the options, which causes catastrophic effects. The second requires two files makes things a bit slower. I use (2) with large files as it gives me the additional benefit of being able to prevent extra loads of the file. The small file acts like a header guard in C. Having the guarantee that my file is sourced at most once gives many advantages. > > I'll probably start calling `disable -f` for all builtins I use. > > I wonder if you might be throwing the baby out with the bathwater here. > Aren't there legitimate use-cases for writing shadowing functions? For > example, what if somebody does =C2=ABzle() { typeset -p funcstack >&2; zl= e "$@" }=C2=BB > for debugging purposes? The flip side is that users often define functions with any name they feel like and are none the wiser if they are shadowing some obscure builtin your code needs. If you want to call the builtin, call the builtin. I'm on the fence on this issue. As long as I don't get too many bug reports because of over-ambitious plugin managers, I'm fine. It does get on my nerves sometimes though. If I could defend against functions shadowing builtins easily, I would. I just don't know how. If `builtin`, `disable`, `setopt`, `unsetopt`, `unset` and `unfunction` are all hidden, escaping the sandbox is tricky. Roman.