From patchwork Mon Nov 19 10:00:32 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Herbert Xu X-Patchwork-Id: 10688347 X-Patchwork-Delegate: herbert@gondor.apana.org.au Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id CA01214D6 for ; Mon, 19 Nov 2018 10:00:38 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id BA5E029C01 for ; Mon, 19 Nov 2018 10:00:38 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id AE65A29C07; Mon, 19 Nov 2018 10:00:38 +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=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3829129C01 for ; Mon, 19 Nov 2018 10:00:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727621AbeKSUXp (ORCPT ); Mon, 19 Nov 2018 15:23:45 -0500 Received: from orcrist.hmeau.com ([104.223.48.154]:43456 "EHLO deadmen.hmeau.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727084AbeKSUXp (ORCPT ); Mon, 19 Nov 2018 15:23:45 -0500 Received: from gondobar.mordor.me.apana.org.au ([192.168.128.4] helo=gondobar) by deadmen.hmeau.com with esmtps (Exim 4.89 #2 (Debian)) id 1gOgM8-00071i-CU; Mon, 19 Nov 2018 18:00:36 +0800 Received: from herbert by gondobar with local (Exim 4.89) (envelope-from ) id 1gOgM4-0001Ej-8s; Mon, 19 Nov 2018 18:00:32 +0800 Date: Mon, 19 Nov 2018 18:00:32 +0800 From: Herbert Xu To: dash@vger.kernel.org, Bernhard =?iso-8859-1?q?=DCbelacker?= , Andrej Shadura Subject: eval: Use the correct expansion mode for fd redirection Message-ID: <20181119100032.aqhjrzgzm6rmq4n5@gondor.apana.org.au> MIME-Version: 1.0 Content-Disposition: inline User-Agent: NeoMutt/20170113 (1.7.2) Sender: dash-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: dash@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP It has been reported that echo test >&$EMPTY_VARIABLE causes dash to segfault. This is a symptom of the bigger problem that dash tries to perform pathname expansion as well as field splitting on the word after >& and <&. This is wrong and this patch fixes it to use the same expansions as done on a normal redirection. Reported-by: Andrej Shadura Signed-off-by: Herbert Xu diff --git a/src/eval.c b/src/eval.c index 6185db4..328fde3 100644 --- a/src/eval.c +++ b/src/eval.c @@ -529,7 +529,7 @@ expredir(union node *n) case NFROMFD: case NTOFD: if (redir->ndup.vname) { - expandarg(redir->ndup.vname, &fn, EXP_FULL | EXP_TILDE); + expandarg(redir->ndup.vname, &fn, EXP_TILDE | EXP_REDIR); fixredir(redir, fn.list->text, 1); } break;