From patchwork Fri Sep 7 08:34:09 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrej Shadura X-Patchwork-Id: 10592275 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-v6csp1459011qvp; Fri, 7 Sep 2018 01:34:40 -0700 (PDT) X-Google-Smtp-Source: ANB0VdYDwQKWszU5uBsi/3ICmXv0GT7X8KyUWUOhLb1lTfHTRuLXY6UU1XAeA483q9T62cKCMGOu X-Received: by 2002:a17:902:d90a:: with SMTP id c10-v6mr6805344plz.35.1536309280542; Fri, 07 Sep 2018 01:34:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1536309280; cv=none; d=google.com; s=arc-20160816; b=L+J/gkVqdOaqWSbOjPxDgnOgdVuhBj1i/RjSsv3Fy3EhX6UgHh3TUBFSniIs9hD3Gt KSUoUswFz5NGDENVDSW3KYOZ9tTNotBGK+om9oPFCUyyDmDXAMkhagYifMD7xqWrM4u/ ZoPAHV7pGUHFl3oiq+2+v/4JY4PhmTtR8Cyt8D1lIFTRJ8Tsuy+z4ESc4/gIzrrDApbU 9qzuEITzbsWBm6+A+5CFs5yiBxaShFmcgFJcy0SHBGxU78HvxwALmL7O9bObyPH55eeg Gke+4x1fajAViJeeHdjTPhGX7p1+zdRNJJGo72WTRu8Opc86IYEghfpOxWkMIC0f4GrS Vs7A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:to:from; bh=l9usxYVZOKHagDIKsOF9BV1un6+qRGs0xdGACuD4JjI=; b=C7oY0eXddjB3Ul4bY9BT4PI17A+zdetBgMCLysj73vneYJOY6WU7Q1HX1ps0PA840C q6IMLSdwSu6qtegO+paKschj9De0FVNHP61X1N0tQSgJ+8zqMhu0JiNK7QB4j7y8YZ+/ AQyIACBjv4rYQYVg2bQCQfEdTACOURzoh69FfSMP4N2+Ss0vnmzaSBTiuBmacZO9BjWs iogYkZnBIRHh88b6cR2n1WjYujgMKCxN2Ck9IREjKRKj6IP3YolEwgwvN3X26ptx0X9R pIPBDctrzp5i/QyHwfsCrqAzedoREWnuqwxJWjqSz06E0e0btbWTBj/E3eAoIW9SxIc/ GJQQ== 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 p187-v6si8299635pfp.27.2018.09.07.01.34.40 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 07 Sep 2018 01:34:40 -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 2C3C42ADD8 for ; Fri, 7 Sep 2018 08:34:40 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 207912ADE1; Fri, 7 Sep 2018 08:34:40 +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 C40782ADD8 for ; Fri, 7 Sep 2018 08:34:39 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B5CE22ADE1; Fri, 7 Sep 2018 08:34:39 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 050552ADD8 for ; Fri, 7 Sep 2018 08:34:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727985AbeIGNOa (ORCPT ); Fri, 7 Sep 2018 09:14:30 -0400 Received: from bhuna.collabora.co.uk ([46.235.227.227]:35234 "EHLO bhuna.collabora.co.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725843AbeIGNOa (ORCPT ); Fri, 7 Sep 2018 09:14:30 -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 39B1F27D872; Fri, 7 Sep 2018 09:34:36 +0100 (BST) From: Andrej Shadura To: dash@vger.kernel.org Subject: [PATCH 1/6] exec: Don't execute binary files if execve() returned ENOEXEC. Date: Fri, 7 Sep 2018 10:34:09 +0200 Message-Id: <20180907083414.14673-2-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> 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: 2208 Lines: 73 From: Adam Borowski Both "dash -c foo" and "./foo" are supposed to be able to run hashbang-less scripts, but attempts to execute common binary files tend to be nasty: especially both ELF and PE tend to make dash create a bunch of files with unprintable names, that in turn confuse some tools up to causing data loss. Thus, let's read the first line and see if it looks like text. This is a variant of the approach used by bash and zsh; mksh instead checks for signatures of a bunch of common file types. POSIX says: "If the executable file is not a text file, the shell may bypass this command execution." Signed-off-by: Adam Borowski Signed-off-by: Andrej Shadura --- src/exec.c | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/src/exec.c b/src/exec.c index 9d0215a..6300001 100644 --- a/src/exec.c +++ b/src/exec.c @@ -148,6 +148,36 @@ shellexec(char **argv, const char *path, int idx) } +/* + * Check if an executable that just failed with ENOEXEC shouldn't be + * considered a script (wrong-arch ELF/PE, junk accidentally set +x, etc). + * We check only the first line to allow binaries encapsulated in a shell + * script without proper quoting. The first line, if not a hashbang, is + * likely to contain comments; even ancient encodings, at least popular + * ones, don't use 0x7f nor values below 0x1f other than whitespace (\t, + * \n, \v, \f, \r), ISO/IEC 2022 can have SI, SO and \e. + */ +STATIC int file_is_binary(const char *cmd) +{ + char buf[128]; + int fd = open(cmd, O_RDONLY|O_NOCTTY); + if (fd == -1) + return 1; + int len = read(fd, buf, sizeof(buf)); + close(fd); + for (int i = 0; i < len; ++i) { + char c = buf[i]; + if (c >= 0 && c <= 8 || + c >= 16 && c <= 31 && c != 27 || + c == 0x7f) + return 1; + if (c == '\n') + return 0; + } + return 0; +} + + STATIC void tryexec(char *cmd, char **argv, char **envp) { @@ -162,6 +192,8 @@ repeat: execve(cmd, argv, envp); #endif if (cmd != path_bshell && errno == ENOEXEC) { + if (file_is_binary(cmd)) + return; *argv-- = cmd; *argv = cmd = path_bshell; goto repeat; From patchwork Fri Sep 7 08:34:10 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrej Shadura X-Patchwork-Id: 10592273 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-v6csp1459120qvp; Fri, 7 Sep 2018 01:34:48 -0700 (PDT) X-Google-Smtp-Source: ANB0VdZGOO87c3l4J1LFwB9vNKN9aHl1gpWJ1DiiArYkID9X/8LHd30fCpZCmT6Bne+xK8Cu8iYC X-Received: by 2002:a17:902:4124:: with SMTP id e33-v6mr6893490pld.48.1536309288230; Fri, 07 Sep 2018 01:34:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1536309288; cv=none; d=google.com; s=arc-20160816; b=CPgLfuybLuwO3uJ1JrkSI7k2fAAZM1SaQn8L3wBNiIaQsNI5MUCZNCo7pbxHcmwAri U1BATWX3d84uwxuuvs66wPDLUN72udP8+Kd/0hO1Up+dH2VqsLSyk//94a6aDvWGypVK XH1HXsK8sJYeV8rcPV78TfAcMTvjicJrcqx4ib5eaOSnw6FoEXYPRurKnyfoDAQ6mvpK fSCcRPyOTm7HhjEYXWD0ZrhOgjs48lfE3hfBUbOGAn0OMZJx+mqXaY5xO85TBbIM55+x K1uSoqQH8IgdMtXvh5LB1KSg5A5vJHZ0WYZmRMx4y6OtLf5Iqw6wM40ehNWF/+/5JuSy m5ng== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:to:from; bh=6E1I5bLfI5POVWFKcko0EBXQ1XtUou/mc+xFs+rC+3Y=; b=KgM+0ckZz7Uwie1tLOXc0KenupgBv4dpQqC4INq5rVKJ6xKitWG7RhqEMIVT6Nh9aw bmMXjgnWzeOO4dhbcJexuUZ/DiS0Yl6N2DXWjTtlXRRm74ADqSVNPuwtyiAWc/ljwod7 AoM4md6EiuBM90YDkzEV9pE7RQIphfu/k4rt3UUZ42iwsPn60zmY73eBu1wKQz+MQuYl FBWjhvLlJ85kisPnEK0vmml+XOHRDL3s4GKl86zps+PcHXwckKNz1NC2wfjeeR+YCY/Y axvlUlOZ1ax2TfdGAG6zBuaL9t7ZcyKco4QFZ4NetLMtpF8SMDzYjLkfd3HeWY+un5ek bNOQ== 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 m18-v6si8013487pgb.136.2018.09.07.01.34.48 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 07 Sep 2018 01:34:48 -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 D1F8C2ADD8 for ; Fri, 7 Sep 2018 08:34:47 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C681D2ADE1; Fri, 7 Sep 2018 08:34:47 +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 772102ADD8 for ; Fri, 7 Sep 2018 08:34:47 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 69DAE2ADE1; Fri, 7 Sep 2018 08:34:47 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0A5A72ADD8 for ; Fri, 7 Sep 2018 08:34:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728024AbeIGNOi (ORCPT ); Fri, 7 Sep 2018 09:14:38 -0400 Received: from bhuna.collabora.co.uk ([46.235.227.227]:35240 "EHLO bhuna.collabora.co.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725843AbeIGNOi (ORCPT ); Fri, 7 Sep 2018 09:14:38 -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 5232C27D871; Fri, 7 Sep 2018 09:34:40 +0100 (BST) From: Andrej Shadura To: dash@vger.kernel.org Subject: [PATCH 2/6] printf: Support \e in "echo" and "printf" builtins. Date: Fri, 7 Sep 2018 10:34:10 +0200 Message-Id: <20180907083414.14673-3-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> 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: 2016 Lines: 57 From: Adam Borowski dash's builtin version of printf doesn't support '\e' (escape), and literaly outputs the 2 characters as-is. As is well known, this sequence is useful, for example, when outputting ANSI escape sequences. While it seems that POSIX does not require that printf support '\e', it is still worth implementing '\e' support, as a way to make the environment more consistent and avoid this small issue when porting scripts from certain other systems or when migrating from bash to dash. Signed-off-by: Adam Borowski [reworded the patch description] Signed-off-by: Andrej Shadura Bug-Debian: http://bugs.debian.org/816295 --- src/bltin/printf.c | 1 + src/dash.1 | 4 ++++ 2 files changed, 5 insertions(+) diff --git a/src/bltin/printf.c b/src/bltin/printf.c index 7785735..9b878da 100644 --- a/src/bltin/printf.c +++ b/src/bltin/printf.c @@ -340,6 +340,7 @@ conv_escape(char *str, int *conv_ch) case '\\': value = '\\'; break; /* backslash */ case 'a': value = '\a'; break; /* alert */ case 'b': value = '\b'; break; /* backspace */ + case 'e': value = '\e'; break; /* escape */ case 'f': value = '\f'; break; /* form-feed */ case 'n': value = '\n'; break; /* newline */ case 'r': value = '\r'; break; /* carriage-return */ diff --git a/src/dash.1 b/src/dash.1 index 32f6ac0..b286f79 100644 --- a/src/dash.1 +++ b/src/dash.1 @@ -1201,6 +1201,8 @@ Subsequent output is suppressed. This is normally used at the end of the last argument to suppress the trailing newline that .Ic echo would otherwise output. +.It Li \ee +Outputs an escape character (ESC). .It Li \ef Output a form feed. .It Li \en @@ -1570,6 +1572,8 @@ The characters and their meanings are as follows: Write a \*[Lt]bell\*[Gt] character. .It Cm \eb Write a \*[Lt]backspace\*[Gt] character. +.It Cm \ee +Write an \*[Lt]escape\*[Gt] (ESC) character. .It Cm \ef Write a \*[Lt]form-feed\*[Gt] character. .It Cm \en From patchwork Fri Sep 7 08:34:11 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrej Shadura X-Patchwork-Id: 10592271 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-v6csp1459279qvp; Fri, 7 Sep 2018 01:34:58 -0700 (PDT) X-Google-Smtp-Source: ANB0VdamPR06dyGPxB/LROvMcwklm/PbcTdXSm214LjwNbWZG6ZULnAVjCxLE/Mk0uBX7INlbxh+ X-Received: by 2002:a17:902:622:: with SMTP id 31-v6mr6824689plg.153.1536309298896; Fri, 07 Sep 2018 01:34:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1536309298; cv=none; d=google.com; s=arc-20160816; b=ditOnkfLG85pdpnYAAlQff5bAW4J+6yoOIynWXhLKrvKbdxn0IOHGL2o4BiEoq/Tcf z8ioPeZq6FR8Grr1Tmi8cM9jyx/tI66DXhwUz2t7mZL5VmUHd8S6Be0/05q4tCujcEGs DEXc3JP1TY88LEhFYgbCzQS1wP3POcMwmeCBV4pMkCTsAN0Ml7GXU0See7YHWSXSt6tM M9kABEBPfJShjZcQqGT5cP64lG+ZQ+6xjFKWqgtX9W/cA8CWJWS+iIOObd0Py/CCXVfr HsQb4BaXg9GBi5AOtjb11B/W9bYFm060zommiilca5s4cLvnG40NEUF2AGVWWQLT2Mbv onSg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:to:from; bh=YY3tnxrxXBKjm2LBXwnAsByPeoHWWKWyttShZsRI1a8=; b=A2ZDeF9BNe45cM2agQycnUe6YxKW7uZ/Kqs+50jJr42LYUJS7NdTWW4YL8YhShs8xK EyyaS/20K5PYpgvDk2RtiFoXd92Zds1AL4nwqApE44YUEtldcWCDMK8qhvvhJeWsDQYj zVD8gWAeJxJKlVofDCA1Rgq9cO6WJdn+jYNMUJMcRwPUkVsVphdKpYNwYAknctSA36kC 3PR7OmVGT4583dY9TYelrlU0phj5WbrFV33U68uF9Hu9hYFZNyPBVaeDSN8I0z7LrPOM xpb7lP7rsNkYOXrkBltOfPMuciF81HWU70cYl+7Fdaa9LNGiztXYZLzTZ6V7LRE/Npp7 H8DA== 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 33-v6si7630792ply.251.2018.09.07.01.34.58 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 07 Sep 2018 01:34:58 -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 7BA212ADD8 for ; Fri, 7 Sep 2018 08:34:58 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 708492ADE1; Fri, 7 Sep 2018 08:34:58 +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 37B312ADD8 for ; Fri, 7 Sep 2018 08:34:58 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2C5332ADE1; Fri, 7 Sep 2018 08:34:58 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B2DBF2ADD8 for ; Fri, 7 Sep 2018 08:34:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728076AbeIGNOs (ORCPT ); Fri, 7 Sep 2018 09:14:48 -0400 Received: from bhuna.collabora.co.uk ([46.235.227.227]:35242 "EHLO bhuna.collabora.co.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725843AbeIGNOr (ORCPT ); Fri, 7 Sep 2018 09:14:47 -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 045BB27D873; Fri, 7 Sep 2018 09:34:47 +0100 (BST) From: Andrej Shadura To: dash@vger.kernel.org Subject: [PATCH 3/6] mkbuiltins: Default to mktemp, not tempfile Date: Fri, 7 Sep 2018 10:34:11 +0200 Message-Id: <20180907083414.14673-4-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> 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: 562 Lines: 24 Don't use tempfile, as it currently runs tempnam(), which is insecure and fails under pseudo(1). Signed-off-by: Andrej Shadura --- src/mkbuiltins | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/mkbuiltins b/src/mkbuiltins index b4d6f4e..f1f2593 100644 --- a/src/mkbuiltins +++ b/src/mkbuiltins @@ -35,7 +35,7 @@ # # @(#)mkbuiltins 8.2 (Berkeley) 5/4/95 -tempfile=tempfile +tempfile=mktemp if ! type tempfile > /dev/null 2>&1 && ! type mktemp > /dev/null 2>&1; then _my_tempfile() { 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; From patchwork Fri Sep 7 08:34:13 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrej Shadura X-Patchwork-Id: 10592267 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-v6csp1459408qvp; Fri, 7 Sep 2018 01:35:07 -0700 (PDT) X-Google-Smtp-Source: ANB0VdZ9kgJJ6VUOPn69gk+KodvP1oqafsMuWpV8qy1QwRoeDbZxllwrUWr+t3y+nFYuwmwxwBOy X-Received: by 2002:a17:902:b947:: with SMTP id h7-v6mr6887334pls.157.1536309307348; Fri, 07 Sep 2018 01:35:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1536309307; cv=none; d=google.com; s=arc-20160816; b=M+52k7VEBOt644u6TEEBjPAIz8SYroOtjqSvW0/6cOOrNBRzF1r9y9ytfmPVyj5qQj JMH62892v4VgZrn128iQ0u/VSyP2Y43JYSpa6QWb3lhYqePdPknftMFgvHUjPlkB3Im2 hQHqh3ANC+GoaiZg/LDiUTdyiugJFDlTvbArz4+2DMwIrYK2ZL3kyUjzUERTCF+JgdGh Z59E3vl/x3kui4nSrIICHaUc7ig+Gt0nuvRdDsS6EmlrGJVgDfNE8E4mf7GUzzJO8Whi 653OBv/3bBgLnfaWCg7QVw/i8m8+3JgEpGDNHu3ptEPNRacqAIKOK7ETMDpWAajwcl6l 2I5g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:to:from; bh=9V6QKBkTcnK3nsSe/F15TsDv6hFr3wUmmGISwDb2FJc=; b=FcYAKEro1/UN8iVG2j7HBL8ckTxn5f6Qae5IfV6L09Zzx81nbtaIDePA4UB8rippun nYrQ2IcK3pls1ZihrCNBnRv6kI157jOxbkotdVJFok9ksV5GSHOID8ozdz+1NA2NS+sL HiHEsOFsQuO2DsRFPPPpjHcVyYE5TSidrYky/K0E9PPVgkMq5IuCZu3Ncv6Ac50eolQ2 NPNZvMpCdCghTeCD9Ui+o769F/hnVydACHBIJzmrACrrc6CuhMXSrx8k/wnKMARYYsKn zjNuc/GrnIFyuykBY3p317WpMBhwL1n8k0r0oouAMlIpC16vvvCdUU1kwxsFFIAeJIOc mFpQ== 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 e18-v6si7731976pgi.133.2018.09.07.01.35.06 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 07 Sep 2018 01:35:07 -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 8B2D42ADD8 for ; Fri, 7 Sep 2018 08:35:06 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7FB732ADE1; Fri, 7 Sep 2018 08:35:06 +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 3ADD62ADD8 for ; Fri, 7 Sep 2018 08:35:06 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2F2472ADE1; Fri, 7 Sep 2018 08:35:06 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C7D402ADD8 for ; Fri, 7 Sep 2018 08:35:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727854AbeIGNO4 (ORCPT ); Fri, 7 Sep 2018 09:14:56 -0400 Received: from bhuna.collabora.co.uk ([46.235.227.227]:35248 "EHLO bhuna.collabora.co.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727848AbeIGNO4 (ORCPT ); Fri, 7 Sep 2018 09:14:56 -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 1B0C327D872; Fri, 7 Sep 2018 09:35:03 +0100 (BST) From: Andrej Shadura To: dash@vger.kernel.org Subject: [PATCH 5/6] eval: Report I/O error on stdout Date: Fri, 7 Sep 2018 10:34:13 +0200 Message-Id: <20180907083414.14673-6-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> 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: 1188 Lines: 46 From: Gerrit Pape ENOSPC as a result of an echo builting failing gives no diagnostic. Just as other shells, dash sets $? to 1, but aside from terminating the script, this does not inform the user what the problem is: zsh: % echo foo > /dev/full echo: write error: no space left on device bash: $ echo foo > /dev/full bash: echo: write error: No space left on device dash: $ echo foo > /dev/full [nothing] Print an error to stderr like the other shells. Suggested by Roger Leigh. Signed-off-by: Gerrit Pape [reworded the patch description with information from the bug] Signed-off-by: Andrej Shadura Bug-Debian: http://bugs.debian.org/690473 --- src/eval.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/eval.c b/src/eval.c index ee43fa9..231d3e0 100644 --- a/src/eval.c +++ b/src/eval.c @@ -955,6 +955,8 @@ evalbltin(const struct builtincmd *cmd, int argc, char **argv, int flags) else status = (*cmd->builtin)(argc, argv); flushall(); + if (outerr(out1)) + warnx("%s: I/O error", commandname); status |= outerr(out1); exitstatus = status; cmddone: From patchwork Fri Sep 7 08:34:14 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrej Shadura X-Patchwork-Id: 10592265 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-v6csp1459488qvp; Fri, 7 Sep 2018 01:35:12 -0700 (PDT) X-Google-Smtp-Source: ANB0VdbpyVzE8M/zUZd6oWFa4UFnW1kBMEPpS3u3pzJ6DgQGshVcvM+AyCXb0YSbjJgaH8/0n9vy X-Received: by 2002:a17:902:8506:: with SMTP id bj6-v6mr6701551plb.210.1536309312532; Fri, 07 Sep 2018 01:35:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1536309312; cv=none; d=google.com; s=arc-20160816; b=Y9esPY99A35ZyH0YAeYQ+1eXNSuv1kBqAdmpFEJqfqpmA/X8xRZE8KAN9dbvfgLx9u kTX9msv9iOgTKyWrKIA7Rmw/q4dY81pXWuALvez2O4Q0/Jo8zqD+sp6MRWbbru6yjocR dqOBmkZi8Uo7l1c+Omz04gCxmmkVJNXG77YVGLIPBOvZ+sORcLNaPwVp1J9Ptk0xqSNV 0Sn0SGA8uVnHj3375CdK2nrU5nuvAiwwC7fE8ytbK0DkUS2d4Ve6pAinNmLsPABrwjQz OpST2zPho0+skRvbygZte4CqrGZdpa4McPE0VfC3Bsez8t4IQTX2lKDIGgwUTO9nDALz rsmQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:to:from; bh=SXPS5JEyZrwCnsHqouZrPT+A96gaT6L7PlS0IRhirq0=; b=CjgHHb307dc5v2LXdZzV/mELsOx810tonEn5OLEntT/9rexiWTVNC1B735cjlai0ul ZbnWA2VR2dPzjUlDJYpwZt1kHI/mgu8MEbzUz668X9dz6lkIUh4J6UqfhrR/lM7eH5wr Q/SNsD6qaK7B2UhCSOvM9nk5whRT0Lb8yVbQQbVll+zW4YayH49YT3fiFLPpDgkEzYu0 YrIuxaMQp7rVKIoWMupEEtVVuo1GeyTS3XlNCux/h4/D8Fpj66ggVWurCmmhXxVd6AS4 kTM7PFZuVHUQt8/mz3laPBv0yKzs61hTK0/tMoJ6RKqKiGnvh1gkBEEc9kPcr1fc4LQW xuug== 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 e22-v6si7630605pfb.185.2018.09.07.01.35.12 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 07 Sep 2018 01:35:12 -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 2BE7F2ADDE for ; Fri, 7 Sep 2018 08:35:12 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2078C2ADE1; Fri, 7 Sep 2018 08:35:12 +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 D23442ADD8 for ; Fri, 7 Sep 2018 08:35:11 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C705D2ADE1; Fri, 7 Sep 2018 08:35:11 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 72B7F2ADD8 for ; Fri, 7 Sep 2018 08:35:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728088AbeIGNPC (ORCPT ); Fri, 7 Sep 2018 09:15:02 -0400 Received: from bhuna.collabora.co.uk ([46.235.227.227]:35254 "EHLO bhuna.collabora.co.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727848AbeIGNPC (ORCPT ); Fri, 7 Sep 2018 09:15:02 -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 76E262706ED; Fri, 7 Sep 2018 09:35:06 +0100 (BST) From: Andrej Shadura To: dash@vger.kernel.org Subject: [PATCH 6/6] main: Print \n upon EOF (CTRL-D) when run interactively Date: Fri, 7 Sep 2018 10:34:14 +0200 Message-Id: <20180907083414.14673-7-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> 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: 1105 Lines: 48 From: Gerrit Pape Exiting dash via a ^D instead of with "exit" causes dash to forget to print a newline. sh-3.1$ sh sh-3.1$ ^D sh-3.1$ dash $ sh-3.1$ It is more neat and tidy to send a newline similarly to what bash does, so it doesn't make the next prompt of the parent shell look ugly. Suggested by jidanni. Signed-off-by: Gerrit Pape Signed-off-by: Jonathan Nieder [reworded the patch description] Signed-off-by: Andrej Shadura Bug-Debian: http://bugs.debian.org/476422 --- src/main.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/main.c b/src/main.c index e8e4256..6d53e00 100644 --- a/src/main.c +++ b/src/main.c @@ -221,8 +221,15 @@ cmdloop(int top) if (!top || numeof >= 50) break; if (!stoppedjobs()) { - if (!Iflag) + if (!Iflag) { + if (iflag) { + out2c('\n'); +#ifdef FLUSHERR + flushout(out2); +#endif + } break; + } out2str("\nUse \"exit\" to leave shell.\n"); } numeof++;