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 074e02c9 for ; Wed, 10 Jul 2019 21:52:47 +0000 (UTC) Received: (qmail 9819 invoked by alias); 10 Jul 2019 21:52:40 -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: 44507 Received: (qmail 11240 invoked by uid 1010); 10 Jul 2019 21:52:40 -0000 X-Qmail-Scanner-Diagnostics: from mail-io1-f51.google.com by f.primenet.com.au (envelope-from , uid 7791) with qmail-scanner-2.11 (clamdscan: 0.101.2/25503. spamassassin: 3.4.2. Clear:RC:0(209.85.166.51):SA:0(-0.7/5.0):. Processed in 0.803962 secs); 10 Jul 2019 21:52:40 -0000 X-Envelope-From: mikachu@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.51 as permitted sender) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=4DuUgBWro0HOveg3J9FlhGtHx0cyJu0ehvhUkEbgHPg=; b=HNXeAVSb3es2S2Je1s95NKpJaoQYpUc7sBZXVhblL1QZAOMm+nZ6mcteDa8uGbXP89 cfCKkX4+GBh6DJbW1OhM1BLpHDhg+X2fiNVWihGFhlaGiWB9u0XXs7gC59ldrBInMVnY tMf3as5QbVc99O67V6Vn9CZg2ZDs9yLXEXLlFkijLny9tNP6eiCs3EKo8BwoCkmtk+K9 lt9N85rPH50urwNXAE8ten2T5VSqdWApoFjxXbErcy7qxOnNM7PlgVmA99H3NZC9LYSL Wp+gxwRmkhMIcD2qp6lv3lbnLFLI8UxZijL/H7qY1j1A9CyPy32cFfjiLdxrnjls/9xS 8ZCQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=4DuUgBWro0HOveg3J9FlhGtHx0cyJu0ehvhUkEbgHPg=; b=cyRZuoeFwEqn5dCZnOZMQlJ/NmnDAbX3YGtRWMyrWu64AgiucmKwyHL+ud1zhMPls1 xDB4oB2o018ptA9ou5WY2KwXtpZT55Rk3Zghv4dHcUg6/Dyi2+kWm58jm24BJbOlRMqS XSCXyWUHxeN0OfoWvFpBIJqpVvPVXNNMEovyEX2aiEs77KjHemBGiFjoRm3R8LiInsaN 2rrf2rRbdPu24y3nBF077sAG+71KS0XWD6Pyi2nQ6/PmxsEnFo45OO7N79b+8mwkbXCv YwwAPTt7S5RmmDGjHDO4OY6jlzBtB/JZc7mlIe4RNbyrFGbkmxMHL5/VtSsVSmt2OFbe 4UUw== X-Gm-Message-State: APjAAAVnMxMBrNbq4hoq7dKAZ+zMB8FuzpIU2N7bPP0l50PqOKBYh/1t 0uKLk4oZ5Ldc+7ZJQCLefCs+rFs1sCj4lmwsenQQGw== X-Google-Smtp-Source: APXvYqzsrAj86Y/Nfxu/rrHCXuNMDchNNR4LmuTJozD2sE7ZMy2BLrV9o7Lf/O23OtRnO5Si/l0pd5gxvy18saW+VW0= X-Received: by 2002:a6b:5f01:: with SMTP id t1mr324377iob.219.1562795527177; Wed, 10 Jul 2019 14:52:07 -0700 (PDT) MIME-Version: 1.0 In-Reply-To: References: From: Mikael Magnusson Date: Wed, 10 Jul 2019 23:52:06 +0200 Message-ID: Subject: Re: Segmentation fault immediately after 'unset PATH' To: Shane Squires Cc: zsh-workers@zsh.org Content-Type: text/plain; charset="UTF-8" On 7/10/19, Shane Squires wrote: > I'm running the most recent version of zsh available on my system (I am not > an admin), which is: > > ------------------ > % zsh --version > zsh 5.3.1 (x86_64-unknown-linux-gnu) > ------------------ > > The following script, when executed, produces a segmentation fault for me. > This is the most minimal example I can construct. > > ------------------ > File run.zsh: > ------------------ > #! /usr/bin/zsh > > run() { > typeset -U path=( $path ) > unset PATH > } > > run > ------------------ > > ------------------ > % ./run.zsh > [1] 13415 segmentation fault ./run.zsh > ------------------ > > As far as I can tell, the problem has to involve all three elements here: > (1) the type of 'path' has to be modified, (2) 'PATH' has to be unset, and > (3) this has to happen inside a function. > > I can imagine that what's going on here is that, for some reason, changing > the type of 'path' from inside a function causes it and 'PATH' to fall "out > of sync" somehow, and this creates problems when 'PATH' is being unset. > But this is extremely vague and speculative, so I won't waste any more time > by discussing it. > > Before anyone lectures me on this, I realize that unsetting 'PATH' is not > advisable in general! It is unfortunately unavoidable in my particular > case. 'PATH' needs to be unset and then immediately set to a new value, > and (because this is being handled in an automated way for many environment > variables) I cannot just immediately re-assign its value. I will find > another workaround on my end, but I'm reporting this here mainly because it > seems to be a genuine bug in zsh. > > Thanks in advance for looking into this-- > Shane This is the backtrace i get with debugging symbols, Program received signal SIGSEGV, Segmentation fault. 0x00000000004832b8 in unsetparam_pm (pm=0x716a70, altflag=1, exp=1) at params.c:3614 3614 pm->gsu.s->unsetfn(pm, exp); (gdb) bt #0 0x00000000004832b8 in unsetparam_pm (pm=0x716a70, altflag=1, exp=1) at params.c:3614 #1 0x000000000048338b in unsetparam_pm (pm=0x6e75b0 , altflag=0, exp=1) at params.c:3634 #2 0x000000000041e22a in bin_unset (name=0x7ffff7fe7760 "unset", argv=0x7ffff7fe77a8, ops=0x7fffffffc2c0, func=31) at builtin.c:3739 #3 0x000000000041093c in execbuiltin (args=0x7ffff7fe7770, assigns=0x0, bn=0x6e37a0 ) at builtin.c:507 #4 0x00000000004394d0 in execcmd_exec (state=0x7fffffffcbe0, eparams=0x7fffffffc800, input=0, output=0, how=18, last1=2, close_if_forked=-1) at exec.c:4096 #5 0x0000000000432dfe in execpline2 (state=0x7fffffffcbe0, pcode=67, how=18, input=0, output=0, last1=0) at exec.c:1929 #6 0x0000000000431a44 in execpline (state=0x7fffffffcbe0, slcode=4098, how=18, last1=0) at exec.c:1660 #7 0x0000000000430d2c in execlist (state=0x7fffffffcbe0, dont_change_job=1, exiting=0) at exec.c:1415 #8 0x0000000000430399 in execode (p=0x7ffff7ff2700, dont_change_job=1, exiting=0, context=0x4c5eca "shfunc") at exec.c:1194 #9 0x000000000043e357 in runshfunc (prog=0x7ffff7ff2700, wrap=0x0, name=0x7ffff7fe7170 "(anon)") at exec.c:5979 #10 0x000000000043db7d in doshfunc (shfunc=0x715450, doshargs=0x7ffff7ff2738, noreturnval=0) at exec.c:5829 #11 0x000000000043ca64 in execshfunc (shf=0x715450, args=0x7ffff7ff2738) at exec.c:5398 #12 0x000000000043c4b9 in execfuncdef (state=0x7fffffffd420, redir_prog=0x0) at exec.c:5264 #13 0x00000000004306a0 in execsimple (state=0x7fffffffd420) at exec.c:1248 #14 0x0000000000430b57 in execlist (state=0x7fffffffd420, dont_change_job=0, exiting=1) at exec.c:1378 #15 0x0000000000430399 in execode (p=0x7ffff7ff2638, dont_change_job=0, exiting=1, context=0x4c8792 "cmdarg") at exec.c:1194 #16 0x0000000000430261 in execstring ( s=0x7fffffffda8b "() { typeset -U path=( $path ); unset PATH }", dont_change_job=0, exiting=1, context=0x4c8792 "cmdarg") at exec.c:1160 ---Type to continue, or q to quit---q Quit (gdb) p pm $1 = (Param) 0x716a70 (gdb) p pm->gsu.s $2 = (GsuScalar) 0x0 (gdb) fr 1 #1 0x000000000048338b in unsetparam_pm (pm=0x6e75b0 , altflag=0, exp=1) at params.c:3634 3634 unsetparam_pm(altpm, 1, exp); (gdb) list 3629 if (oldpm && !altpm->level) { 3630 oldpm->old = NULL; 3631 /* fudge things so removenode isn't called */ 3632 altpm->level = 1; 3633 } 3634 unsetparam_pm(altpm, 1, exp); 3635 } 3636 3637 zsfree(altremove); 3638 } (gdb) p altpm $3 = (Param) 0x716a70 Adding a check for that particular NULL causes the following backtrace instead: Program received signal SIGSEGV, Segmentation fault. 0x00000000004868a5 in scanendscope (hn=0x6e7ce0 , flags=0) at params.c:5621 5621 pm->old = tpm->old; (gdb) p pm $1 = (Param) 0x6e7ce0 (gdb) p pm->old $2 = (Param) 0x0 (gdb) p pm $3 = (Param) 0x6e7ce0 (gdb) p tpm $4 = (Param) 0x0 (gdb) bt #0 0x00000000004868a5 in scanendscope (hn=0x6e7ce0 , flags=0) at params.c:5621 #1 0x000000000044ab7f in scanmatchtable (ht=0x7069c0, pprog=0x0, sorted=0, flags1=0, flags2=0, scanfunc=0x4867af , scanflags=0) at hashtable.c:428 #2 0x000000000044ac09 in scanhashtable (ht=0x7069c0, sorted=0, flags1=0, flags2=0, scanfunc=0x4867af , scanflags=0) at hashtable.c:444 #3 0x0000000000486667 in endparamscope () at params.c:5587 #4 0x000000000043e38c in runshfunc (prog=0x7ffff7ff2700, wrap=0x0, name=0x7ffff7fe7170 "(anon)") at exec.c:5984 #5 0x000000000043db7d in doshfunc (shfunc=0x715450, doshargs=0x7ffff7ff2738, noreturnval=0) at exec.c:5829 #6 0x000000000043ca64 in execshfunc (shf=0x715450, args=0x7ffff7ff2738) at exec.c:5398 #7 0x000000000043c4b9 in execfuncdef (state=0x7fffffffd420, redir_prog=0x0) at exec.c:5264 #8 0x00000000004306a0 in execsimple (state=0x7fffffffd420) at exec.c:1248 #9 0x0000000000430b57 in execlist (state=0x7fffffffd420, dont_change_job=0, exiting=1) at exec.c:1378 #10 0x0000000000430399 in execode (p=0x7ffff7ff2638, dont_change_job=0, exiting=1, context=0x4c8792 "cmdarg") at exec.c:1194 #11 0x0000000000430261 in execstring ( s=0x7fffffffda8b "() { typeset -U path=( $path ); unset PATH }", dont_change_job=0, exiting=1, context=0x4c8792 "cmdarg") at exec.c:1160 #12 0x0000000000458f20 in init_misc ( cmd=0x7fffffffda8b "() { typeset -U path=( $path ); unset PATH }", zsh_name=0x7fffffffda84 "zsh") at init.c:1374 #13 0x000000000045a309 in zsh_main (argc=3, argv=0x7fffffffd608) at init.c:1758 #14 0x000000000040fa46 in main (argc=3, argv=0x7fffffffd608) at ./main.c:93 -- Mikael Magnusson