From patchwork Thu Sep 1 20:18:30 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Harald van Dijk X-Patchwork-Id: 9309865 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.web.codeaurora.org (Postfix) with ESMTP id 2C48B60760 for ; Thu, 1 Sep 2016 22:19:09 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 103E829561 for ; Thu, 1 Sep 2016 22:19:09 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0511629563; Thu, 1 Sep 2016 22:19:09 +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=-6.9 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, T_TVD_MIME_EPI 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 D33FB29561 for ; Thu, 1 Sep 2016 22:19:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751693AbcIAWTH (ORCPT ); Thu, 1 Sep 2016 18:19:07 -0400 Received: from mailfilter1-k0683s008.csv-networks.nl ([92.48.231.157]:53739 "EHLO mailfilter1-k0683s008.csv-networks.nl" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751020AbcIAWTG (ORCPT ); Thu, 1 Sep 2016 18:19:06 -0400 Received: from [84.244.151.217] (helo=hosting12.csv-networks.nl) by mailfilter1-k0683s008.csv-networks.nl with esmtps (TLSv1:AES256-SHA:256) (Exim 4.72) (envelope-from ) id 1bfYVd-00036L-E5; Thu, 01 Sep 2016 20:22:49 +0000 Received: from home.gigawatt.nl ([83.163.3.213] helo=[192.168.178.22]) by hosting12.csv-networks.nl with esmtpa (Exim 4.85) (envelope-from ) id 1bfYRU-0002nb-1q; Thu, 01 Sep 2016 22:18:32 +0200 Subject: Re: [BUG] regression in builtin echo To: Luigi Tarenga , dash@vger.kernel.org References: From: Harald van Dijk Message-ID: <3efcd42c-e20b-3506-3d62-69b85c027ef4@gigawatt.nl> Date: Thu, 1 Sep 2016 22:18:30 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.2.0 MIME-Version: 1.0 In-Reply-To: Sender: dash-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: dash@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP On 01/09/16 10:13, Luigi Tarenga wrote: > hi, > I just find a problem in the dash distributed with arch linux. > I didn't tested from dash source but the bug can be easily > checked: > > dash 0.5.9-1 > > $ echo one two three > one two three > $ > $ echo -n one two three > one$ Yikes. > with -n option it stop after printing one more parameter... > do you have the same problem or it's caused by a patch in arch? That's caused by , not by Arch. It's scary that this has gone totally unnoticed for more than a year. While the original code implementing the echo command was overly complicated, the simplified version does not do the right thing, as you noticed. Here's another attempt at a simplified implementation. > Luigi diff --git a/src/bltin/printf.c b/src/bltin/printf.c index 9673e10..b7b6d68 100644 --- a/src/bltin/printf.c +++ b/src/bltin/printf.c @@ -447,16 +447,20 @@ echocmd(int argc, char **argv) nonl = *++argv ? equal(*argv, "-n") : 0; argv += nonl; - do { - int c; + if (*argv) { + for (;;) { + if (print_escape_str("%s", NULL, NULL, *argv)) + return 0; + + if (!*++argv) + break; + + out1c(' '); + } + } - if (likely(*argv)) - nonl += print_escape_str("%s", NULL, NULL, *argv++); - if (nonl > 0) - break; + if (!nonl) + out1c('\n'); - c = *argv ? ' ' : '\n'; - out1c(c); - } while (*argv); return 0; }