Path: csiph.com!goblin1!goblin.stu.neva.ru!usenet.stanford.edu!not-for-mail From: "Franklin, Jason" Newsgroups: gnu.bash.bug Subject: Re: [bug] Segmentation fault in the "fc" builtin Date: Tue, 5 May 2020 12:16:37 -0400 Organization: Quoin, Inc. Lines: 69 Approved: bug-bash@gnu.org Message-ID: References: <06953bf8-5526-bb86-b878-2dcf9864acec@quoininc.com> <6ec4bd02-4aa3-3e03-980d-9744669c7270@case.edu> <0774c9ef-a992-8353-6e07-3e9c6e56d923@quoininc.com> NNTP-Posting-Host: lists.gnu.org Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Trace: usenet.stanford.edu 1588695404 26273 209.51.188.17 (5 May 2020 16:16:44 GMT) X-Complaints-To: action@cs.stanford.edu Cc: brandon.pfeifer@quoininc.com To: chet.ramey@case.edu, bug-bash@gnu.org Envelope-to: bug-bash@gnu.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=quoininc.com; s=google; h=subject:to:cc:references:from:autocrypt:organization:message-id :date:user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=6Q0jJHL2MIcWi4baF1PTd6PVACNljPZ3c7lT5+c4eGE=; b=Std/yqDLy+BtsQzuYTJ1mJSD7ucKsr/Pkz7tHSeFcl0VMPB987I0yc6GWJuZKjP4WQ xpIzO6qc5UQoS4c6izatzXWnuf/ZCb4pyqigYg2u7UFRfFwjsOPiWjbZvjDUuOQoocLC HFk/pHVsFI6Aa2Xrehwz/h+nFPzHio7uF04ic= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:autocrypt :organization:message-id:date:user-agent:mime-version:in-reply-to :content-language:content-transfer-encoding; bh=6Q0jJHL2MIcWi4baF1PTd6PVACNljPZ3c7lT5+c4eGE=; b=RImM9FCfY8rGsD7OKvPuTGiUyAUKf+NsHL1zLuKag9KhyxOIfge9/oQ4HswIxtirFd j/00V1Dp0Gx2aifmXSnmF5zSzjb3gCuBmXi+bfCinGJlC5EK8M2Nj32Nkt8qDcID4Zcj yzyjpYSLPHeDlsqkOJ6bXc2z0cS7YU3KPuxep2tjg4ByqDxzgCmMR9bop5aqXehYw9zd Pa64auk5dfNSDKlU/OU4VVcMC3SCoX+txzzwZn+PIdX1xm+E1l51kQu70Hc02MHhYaRG mGm4QL9VX5R6xEskM2r/z6pOBV6tIbSC2puRwN1NE+SkBL3nniZc4YbK3sHe3R9d5Sn8 UPYQ== X-Gm-Message-State: AGi0PuagE9D3LptcQ2vpCCp1+AnWj9BW+btAQHSrYHXqdhUO5Y71f0RU gDOZR5A8Pl8tTvOeyCh/x/dnhQ== X-Google-Smtp-Source: APiQypJi+Q13oLFi8IUTek6tJY0+B+dPq3NBF3Sjm+eVfSj2FykmvqEJefWa20fIfyTcoRRKnQ0sVQ== X-Received: by 2002:a37:7903:: with SMTP id u3mr4331930qkc.357.1588695398970; Tue, 05 May 2020 09:16:38 -0700 (PDT) Autocrypt: addr=jason.franklin@quoininc.com; keydata= mQGNBF0+/NIBDADgQkZ3EB0NAIDGfkAFDaep9VtVjYV6bfnkUtm4g2VAxMeplvjxAA69cV8h 2n7+HxUB3RnxxkTeKBZY/k/jt0HYAkuCpaYm3fpk8aNCmW8q6qZearU5CwyRgJQMwh2uzA98 otxtt5I2DGLs1vlYulSFgIEaSfv9zEnR8Ss4dNhre4nhiETbG4kA7mZAa7Ot7cc+1wMJDvTe 4ifQ8auIiebGkHUqDiIHZLMgSt0lDoBT653Ohg7+iCqzA/e5/Vzj5zzsCnlfM+bSIpLU5gSR Ea1v1WV9RoNC+DzJJ1kihb/90gtcsYLv6LVw8Orh3G8WNTfLb30Cd68kAPu7At14taw7QFHr 5FsY9jEF41yCl0bvNsGCypiH3qfgepGiP1sGy88jGQCERK5dkfnx6ai3F71fO71UfcGxL2QD fZHu/SeNkE8AaiDOcwIMh+ADXUTUhdMi2/vRblVJHi2vCjo7AsAzV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ym25LONHlcChe45ptWkrtnaR0New3L6 4CRwZHCs/3EkTA9qbeeXxM3f6zCtSN7Gk2VJyGaRiOOlaRNPcjrQa9YQAIiJ/mPxLTZ7nUiD NDIlzys55GT7NcKP98uTmB4YOqmnpDGuPJVy1+yglj6Li3TfQ4lw8xtcHsyKh32hCqaTB/NZ 5b/7GrmWSzVDdU+VS2dqHbgbMUp4zLTxmMrXJX1qzqW/6OeblfosRZLt2uWV7X+mDidg7ucd AdlsPF403hhWS8JgqXXkPCftW5sFQ72DY2Re User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.7.0 In-Reply-To: <6ec4bd02-4aa3-3e03-980d-9744669c7270@case.edu> Content-Language: en-US Received-SPF: permerror client-ip=2607:f8b0:4864:20::731; envelope-from=jason.franklin@quoininc.com; helo=mail-qk1-x731.google.com X-detected-operating-system: by eggs.gnu.org: No matching host in p0f cache. That's all we know. X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, T_SPF_PERMERROR=0.01, URIBL_BLOCKED=0.001 autolearn=_AUTOLEARN X-Spam_action: no action X-BeenThere: bug-bash@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Bug reports for the GNU Bourne Again SHell List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Mailman-Original-Message-ID: <0774c9ef-a992-8353-6e07-3e9c6e56d923@quoininc.com> X-Mailman-Original-References: <06953bf8-5526-bb86-b878-2dcf9864acec@quoininc.com> <6ec4bd02-4aa3-3e03-980d-9744669c7270@case.edu> Xref: csiph.com gnu.bash.bug:16284 On 5/5/20 11:41 AM, Chet Ramey wrote: > Thanks for the report and your careful analysis. > >> >> Allow me to explain the reasoning behind the patch... >> >> From the CHANGES file, we see this note concerning the "fc" builtin: >> >> b. The fc builtin now interprets -0 as the current command line. > Yes, this is from one of the bash-4.3 testing releases. It's in response > to this message: > > https://lists.gnu.org/archive/html/bug-bash/2013-08/msg00037.html > > and deliberately works only for -l. > > The question is what to do about the cases where -l isn't supplied, as > you observed. Dumping core is definitely the worst of the options. > >> Our solution does not remove the last history item when the user passes >> "-0" to tell "fc" to include it in the history and the list to edit. > > The issue I have with this solution is that it leads to an infinite loop > if the user doesn't change the command in the editor. If you use `fc -s -0' > the shell runs fc recursively until it runs out of stack space and then > dumps core. You're right here, I think. With this, it still seems easy to shoot yourself in the foot. As you say below, though, it might be reasonable to call this a user error. Though the command does offer this negative possibility, it is logically consistent with the intent. > You could easily say that this falls into the category of user error, and > I wouldn't argue, but as you also observe, there's nothing in the man page > prohibiting or even warning against it. Agreed. This is an undocumented feature, which is why Brandon and I had a bit of trouble figuring out what "should" happen. :/ > I'm leaning towards making 0 and -0 out-of-range errors for the non-listing > case. This is what other shells do (the netbsd and freebsd shells being > notable exceptions). Well, I think 0 and -0 have different intentions as it stands. Currently, "0" indicates the command right before the "fc" invocation that caused the editing or listing. This shouldn't ever cause an infinite loop and should not be an out-of-range error, I assert. Example session: bash-5.0$ true # example command bash-5.0$ fc -l 0 48 true # example command bash-5.0$ Thus, the argument in question is specifically "-0" proper. This, to me, means "the fc command itself" that did this work. Would a good solution be to have "0" function as-is, but have "-0" only be valid in the listing case? This would avoid the problem above. Of course, documenting the intent of the feature would be key to making the change a successful one! Thanks, Chet! -- Jason Franklin