From patchwork Fri Sep 7 08:34:12 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Andrej Shadura X-Patchwork-Id: 10592269 X-Patchwork-Delegate: herbert@gondor.apana.org.au Delivered-To: konstantin@linuxfoundation.org Received: by 2002:a0c:fb06:0:0:0:0:0 with SMTP id c6-v6csp1459327qvp; Fri, 7 Sep 2018 01:35:02 -0700 (PDT) X-Google-Smtp-Source: ANB0VdblV0TNknQo+dyfRbD0xjP2KPeYStCWU38Mjev2c6FyPZMae7+zkoWy5Z1qWlvCKN9hKMdM X-Received: by 2002:a63:da04:: with SMTP id c4-v6mr7169257pgh.398.1536309302844; Fri, 07 Sep 2018 01:35:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1536309302; cv=none; d=google.com; s=arc-20160816; b=S5gnFWBWV4c6S5UQKxjQLcRQ/Ozr+GiywjDtBJYAuTKPW1fX1y1DDiQN65rhXalyqG AjVX62PVX77smm78pXznZActnUp/iQnPHHwXe8i82cCfZgcmwH8+Xm7KsFaIKjbzU6j3 1jBS9XT5yp8wam9s9ywxFo13nuSTKfStrDQvdhQtp+n+E7SZds+rg4su0VS7cifxdpqm ePFwt4noZbPVIom/9aHLo+UAPJoPqyg5tPEHtIfiunnoUv2oPMlDiZ08RiTwqm4XcY82 HoDXuHErP5kSP1pzTDtKPpZxDNiXQASibRW4brALTa5lP3lyGz0zty/nPkyalsVF0OSw iR5w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:to:from; bh=kHNh+Aepr5Mr134FNpfBtOlmoA6dXYcpphxytz4NVrc=; b=B6F25J4ZLVhbKoITJ3ZrTmAhEaSzb9iqGqAMH3EqGLGOa8IhayMgZjwFzZmh5zv4/8 ylsWggbe9GunwXVe2Gg5naKocBvn5/q7o8G0zSKXCCg0GMO1Uu02bFEgqNClom8v6M+x g+jWI9JIPKew75OikhLed+0zZqhLL4gE6GtVfhZCiX0fMXbnGgQ382TWlZhnyiU6pQ9n opB8ikE+KXXv8X3YFNYkHahBwFxoVfaZy6c29F76e+DYJFGJdpBtKK2uJPSRTRLLlRvE GDQcM6salDM+UHR6lQuYy9DP/B2NJyaPD/qWch1nn2wEjHshu8Q1SZ7dr/R6Wrh0GrDS jbbQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of dash-owner@kernel.org designates 198.145.29.98 as permitted sender) smtp.mailfrom=dash-owner@kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=collabora.co.uk Return-Path: Received: from mail.wl.linuxfoundation.org (mail.wl.linuxfoundation.org. [198.145.29.98]) by mx.google.com with ESMTPS id m24-v6si8023653pfk.56.2018.09.07.01.35.02 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 07 Sep 2018 01:35:02 -0700 (PDT) Received-SPF: pass (google.com: domain of dash-owner@kernel.org designates 198.145.29.98 as permitted sender) client-ip=198.145.29.98; Authentication-Results: mx.google.com; spf=pass (google.com: domain of dash-owner@kernel.org designates 198.145.29.98 as permitted sender) smtp.mailfrom=dash-owner@kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=collabora.co.uk Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7A93A2ADD8 for ; Fri, 7 Sep 2018 08:35:02 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6E96A2ADE1; Fri, 7 Sep 2018 08:35:02 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=unavailable version=3.3.1 Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2945E2ADD8 for ; Fri, 7 Sep 2018 08:35:02 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1C03E2ADE1; Fri, 7 Sep 2018 08:35:02 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 91FFC2ADD8 for ; Fri, 7 Sep 2018 08:35:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728087AbeIGNOx (ORCPT ); Fri, 7 Sep 2018 09:14:53 -0400 Received: from bhuna.collabora.co.uk ([46.235.227.227]:35244 "EHLO bhuna.collabora.co.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727848AbeIGNOw (ORCPT ); Fri, 7 Sep 2018 09:14:52 -0400 Received: from localhost (2a02-ab04-03b9-5e00-0000-0000-0000-0003.dynamic.v6.chello.sk [IPv6:2a02:ab04:3b9:5e00::3]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) (Authenticated sender: andrewsh) by bhuna.collabora.co.uk (Postfix) with ESMTPSA id DB56B27D872; Fri, 7 Sep 2018 09:34:57 +0100 (BST) From: Andrej Shadura To: dash@vger.kernel.org Subject: [PATCH 4/6] eval: Avoid crash when redirecting to file descriptor in expredir Date: Fri, 7 Sep 2018 10:34:12 +0200 Message-Id: <20180907083414.14673-5-andrew.shadura@collabora.co.uk> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180907083414.14673-1-andrew.shadura@collabora.co.uk> References: <20180907083414.14673-1-andrew.shadura@collabora.co.uk> MIME-Version: 1.0 Sender: dash-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: dash@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP X-Virus-Scanned: ClamAV using ClamSMTP Status: O Content-Length: 1029 Lines: 38 From: Bernhard Übelacker When trying to redirect output to a filedescriptor contained in an environment variable, but if that variable is empty, dash crashes with a segmentation fault. To reproduce, run the following: echo test >&$EMPTY_VARIABLE Signed-off-by: Andrej Shadura Bug-Debian: https://bugs.debian.org/861354 --- src/eval.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/eval.c b/src/eval.c index 6185db4..ee43fa9 100644 --- a/src/eval.c +++ b/src/eval.c @@ -516,6 +516,7 @@ expredir(union node *n) for (redir = n ; redir ; redir = redir->nfile.next) { struct arglist fn; + fn.list = NULL; fn.lastp = &fn.list; switch (redir->type) { case NFROMTO: @@ -530,6 +531,8 @@ expredir(union node *n) case NTOFD: if (redir->ndup.vname) { expandarg(redir->ndup.vname, &fn, EXP_FULL | EXP_TILDE); + if (!fn.list) + sh_error("ambiguous redirect"); fixredir(redir, fn.list->text, 1); } break;