From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.org/gmane.linux.lib.musl.general/11026 Path: news.gmane.org!.POSTED!not-for-mail From: Rich Felker Newsgroups: gmane.linux.lib.musl.general Subject: Re: behavior errata Date: Sat, 11 Feb 2017 19:02:39 -0500 Message-ID: <20170212000239.GD1520@brightrain.aerifal.cx> References: <3DD147FE-6B27-41BB-8C09-4F569D62F74B@chuckremes.com> Reply-To: musl@lists.openwall.com NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Trace: blaine.gmane.org 1486857774 23793 195.159.176.226 (12 Feb 2017 00:02:54 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Sun, 12 Feb 2017 00:02:54 +0000 (UTC) User-Agent: Mutt/1.5.21 (2010-09-15) To: musl@lists.openwall.com Original-X-From: musl-return-11041-gllmg-musl=m.gmane.org@lists.openwall.com Sun Feb 12 01:02:49 2017 Return-path: Envelope-to: gllmg-musl@m.gmane.org Original-Received: from mother.openwall.net ([195.42.179.200]) by blaine.gmane.org with smtp (Exim 4.84_2) (envelope-from ) id 1cchcu-0005qM-N8 for gllmg-musl@m.gmane.org; Sun, 12 Feb 2017 01:02:48 +0100 Original-Received: (qmail 13982 invoked by uid 550); 12 Feb 2017 00:02:52 -0000 Mailing-List: contact musl-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-ID: Original-Received: (qmail 13964 invoked from network); 12 Feb 2017 00:02:52 -0000 Content-Disposition: inline In-Reply-To: <3DD147FE-6B27-41BB-8C09-4F569D62F74B@chuckremes.com> Original-Sender: Rich Felker Xref: news.gmane.org gmane.linux.lib.musl.general:11026 Archived-At: On Sat, Feb 11, 2017 at 05:28:37PM -0600, lists@chuckremes.com wrote: > While debugging an issue where a child process’s errno was getting > clobbered, discovered that musl was doing the clobbering in a call > to strftime (that did NOT fail). > > I understand the contract of libc calls is that errno can be > clobbered at any time. However, it’s a behavior difference between > musl and other libc’s that I have tested against. > > Here’s the repro code. > > https://gist.github.com/chuckremes/698b0ee5d1279374cb1ef3add82a6f18 > > I had a nice chat with some folks on IRC about this. They indicated > that it might get “fixed” just to be nice but there is no > requirement to do so. Someone even made the (evil but funny) > suggestion that musl should clobber errno between every non-failing > call just to see how much code in the wild would explode. Please > don’t. :) > > Thanks for your attention. Hi. Indeed, errno is only meaningful after a function that returns an error and sets it. Most other functions, except a few explicitly specified not to, can clobber errno with any nonzero value. While the above behavior might change (especially if it's found that we're doing a wasteful operation that's causing errno to be set), musl will never guarantee non-clobbering of errno in cases where it's allowed to be clobbered, so programs that wrongly depend on that might break again in the future if something changes again. You really just need to fix the code that's wrongly relying on errno being preserved on success. Only check errno when an error is returned. Rich