From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=-3.4 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED, T_SCC_BODY_TEXT_LINE,UNPARSEABLE_RELAY autolearn=ham autolearn_force=no version=3.4.4 Received: (qmail 15720 invoked from network); 9 Jun 2022 17:30:00 -0000 Received: from zero.zsh.org (2a02:898:31:0:48:4558:7a:7368) by inbox.vuxu.org with ESMTPUTF8; 9 Jun 2022 17:30:00 -0000 ARC-Seal: i=1; cv=none; a=rsa-sha256; d=zsh.org; s=rsa-20210803; t=1654795800; b=OgQ4UW91WKfuI/gkuCTUgUbAhEF133lQSemJGWn+yPRPApWooJsRghHK4EDoQcUdHYCA7CjfN/ uvl+m66fWIttMGOmMKgcvV3H+qtptCh75VlAFjQ3S+J8K/wMmu++JAQnVw2KmnqZS+ncfpwEd7 ckZis+z92uwBrb3K6AgCE2lpQHe4IPZuAo/7dqLw+2O0rIuvmwinfnJIJa3shPXhVYEGCiY41K 8Gq61RXnvr58QW3BKxtXX0L21m1FOouAgSO/f3mD1/Hn1d24iqtfWLtNrlcYm4pcON7U/4gUSX 7GTY7Ejcqraw3OY2kaHTP3Mbj1T+C2s3QEaWZVo2tPkjPg==; ARC-Authentication-Results: i=1; zsh.org; iprev=pass (mail-oa1-f46.google.com) smtp.remote-ip=209.85.160.46; dkim=pass header.d=gmail.com header.s=20210112 header.a=rsa-sha256; dmarc=pass header.from=gmail.com; arc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed; d=zsh.org; s=rsa-20210803; t=1654795800; bh=nmC0X3dPXYSus2eTeXNjNU1yi+SZdmxVryzqDCD+kbM=; h=List-Archive:List-Owner:List-Post:List-Unsubscribe:List-Subscribe:List-Help: List-Id:Sender:Content-Type:MIME-Version:Message-ID:Subject:To:From:Date: DKIM-Signature:DKIM-Signature; b=dZ5rVrgHB3/j1VJfOZGRuBLLM/LPRifR4U1SVrCVXwAarx2TZ6/T9Bcy0qpaPXjEAv+qhir+3L PoaYkM6JQFQ3r6jt89jg3mHLeuyL0TXMpyp4mxXDAcjuHbsAH5FLQVFszNQWCHFh+i2mz3FCYe Lvo1wNjHVrSJENziJ0lFm7qS7OHsKKR5YXf8oOSksjlVT34gZi2Xfc7st4KdBqskmD8CNCXptr UrdQH7kJ72Xp8s8H7S8MBmNbG4x4XyIRVpMhaDeDM+cbRwSXPiflUmfE52Pl7xyDRfQ5C5JyFY Wk+/9u8ALvHiNNOtg6+2fPhYq1cLsEEyokTFaqHZFZb+tg==; DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=zsh.org; s=rsa-20210803; h=List-Archive:List-Owner:List-Post:List-Unsubscribe: List-Subscribe:List-Help:List-Id:Sender:Content-Type:MIME-Version:Message-ID: Subject:To:From:Date:Reply-To:Cc:Content-Transfer-Encoding:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:In-Reply-To:References; bh=T3bDtxYc0nJWzqtu0hZNfJOiXPtePSjG34EqFKBfGmg=; b=JIJBf+eaDDO6NzyhfnffOqQO8G DkTj6jL69ZG/x+EUzNobm0wviMWMz/9xUANT+Znti/4vBikrSWGk3h2iP/h6eSf8ASUqAph+oyr6W 2HinNeC2vE0AJDdtUbTZhE8wX486ky62Nt3k80tcVIUBE6gUO7LYvm2EsrUaFzeaak4WQOGDFtHn4 7cjhZ3o+84KYaXqbWIshwDroubXEzX0/09Wbohbfu+L9uSj2J6tNzV+n3uq76aABUg3lEtgQOuxru E9FCkQ8HqGUkrqawut4JTxqjVJjscVjrfOwIfDqtUU6ZHaLmCUcUEvLDg7VOG239Y/o3YGO/5Wwq2 QBt8VGsA==; Received: from authenticated user by zero.zsh.org with local id 1nzLyp-000Fw7-G7; Thu, 09 Jun 2022 17:29:59 +0000 Authentication-Results: zsh.org; iprev=pass (mail-oa1-f46.google.com) smtp.remote-ip=209.85.160.46; dkim=pass header.d=gmail.com header.s=20210112 header.a=rsa-sha256; dmarc=pass header.from=gmail.com; arc=none Received: from mail-oa1-f46.google.com ([209.85.160.46]:36519) by zero.zsh.org with esmtps (TLS1.3:TLS_AES_128_GCM_SHA256:128) id 1nzLyB-000Fce-6I; Thu, 09 Jun 2022 17:29:20 +0000 Received: by mail-oa1-f46.google.com with SMTP id 586e51a60fabf-fe4ac3b87fso305552fac.3 for ; Thu, 09 Jun 2022 10:29:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=date:from:to:subject:message-id:mail-followup-to:mime-version :content-disposition; bh=T3bDtxYc0nJWzqtu0hZNfJOiXPtePSjG34EqFKBfGmg=; b=pzTIQmlTcxougQfXYWLe+6aZqI5WLHqm5+HabHYMKkXjzB3R159ZF3v/8pIzpXb2U8 VO47xooVW8pI1IhJY/pZ8ASlM+eU0pa0ar82UlNGlqZZ9Uz4LwPAiu5A7wZQkOC9/FOA +e+gwXFwdQyk2damcI7rgcwLBpPwsjQgL3HIUSkAmBzfR52Fuq6c+Ei8K9QBhC/58YYL ti7O4ymQqdWGDuSbQiF8emGgOeo+Knt9aGL2Rf4DgGNefaojozOfsFX//pzvwcfJFJ9q BKASNwN7cVQMCkSEUFUyvucmoHVnG9650Xj/7Z6G4Nkh1h3D9b7AU0vTLZN3tEmcJIhy cAow== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:subject:message-id:mail-followup-to :mime-version:content-disposition; bh=T3bDtxYc0nJWzqtu0hZNfJOiXPtePSjG34EqFKBfGmg=; b=qh57YuaHTMAXtmbdETesfe64NTOxcEZmoJUC3q5ZzdvfpMmdxCDfL/lEccBqa23NbM drAkJcUI2tp7s7IMJErJ8kz6OFsYn5/rBXXJPQDzvuBdfbrJWzLxZAo2Z+ntbVzwsVt2 hSAOUIOYLT66DjICm0Z5LJcvCe7Ih1iP2tps0xSy+A/15e9qXiJ/1JmP6EcO8rcxg0fQ jGidcdI4iAjc9dV11HKQO9x8iGMTc/jZIlIUioVT3HhREt18wBi1Rtpo2OVT1KI+AiPd K8PiL3MK+NX0vDNE8dgcvCylI08c/zGUW6XM3ULbEZHgl2waASCwG/Y2+coLp56gEPGa m5lg== X-Gm-Message-State: AOAM530uUw2s7ryogKBSUv0/R/yLMvhGUM2GOaCmuRC255fjqn527M+N In3MV/5QdJB6vPpkIIYu767Mtl418xWMBQ== X-Google-Smtp-Source: ABdhPJxrK6LAqoQKJdfFCS5Gluj4BvGQiZyp+ROUTKk/78zK0uaIDRjVSjc0FyxGIK4KI7MSrA1zyw== X-Received: by 2002:a05:6870:8985:b0:da:b3f:3253 with SMTP id f5-20020a056870898500b000da0b3f3253mr2336812oaq.259.1654795757155; Thu, 09 Jun 2022 10:29:17 -0700 (PDT) Received: from CptOrmolo.darkstar (cpe-76-184-110-212.tx.res.rr.com. [76.184.110.212]) by smtp.gmail.com with ESMTPSA id l9-20020aca1909000000b00325cda1ff9esm711398oii.29.2022.06.09.10.29.16 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 09 Jun 2022 10:29:16 -0700 (PDT) Date: Thu, 9 Jun 2022 12:29:13 -0500 From: Matthew Martin To: zsh-workers@zsh.org Subject: Segfault copying an emulated function outside of emulation Message-ID: Mail-Followup-To: zsh-workers@zsh.org MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline X-Seq: 50359 Archived-At: X-Loop: zsh-workers@zsh.org Errors-To: zsh-workers-owner@zsh.org Precedence: list Precedence: bulk Sender: zsh-workers-request@zsh.org X-no-archive: yes List-Id: List-Help: List-Subscribe: List-Unsubscribe: List-Post: List-Owner: List-Archive: ahmubashshir on IRC reported the following causes zsh to segfault zsh -c 'emulate sh -c "foo(){ :; }"; functions -c foo bar' This seems to be because bin_functions calls sticky_emulation_dup with sticky which is NULL outside of emulation. The below patch fixes the segfault, but I can't claim to be terribly familiar with the code. diff --git a/Src/builtin.c b/Src/builtin.c index 1cef7cce8..4a220ccd7 100644 --- a/Src/builtin.c +++ b/Src/builtin.c @@ -3304,7 +3304,7 @@ bin_functions(char *name, char **argv, Options ops, int func) if (newsh->redir) newsh->redir->nref++; if (shf->sticky) - newsh->sticky = sticky_emulation_dup(sticky, 0); + newsh->sticky = sticky_emulation_dup(shf->sticky, 0); shfunctab->addnode(shfunctab, ztrdup(argv[1]), &newsh->node); return 0; }