From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.org/gmane.linux.lib.musl.general/9958 Path: news.gmane.org!not-for-mail From: Alexander Monakov Newsgroups: gmane.linux.lib.musl.general Subject: Re: Removing stupid, spurious UB in stdio (bikeshed time) Date: Wed, 27 Apr 2016 10:56:25 +0300 (MSK) Message-ID: References: <20160426221815.GA24105@brightrain.aerifal.cx> Reply-To: musl@lists.openwall.com NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII X-Trace: ger.gmane.org 1461743802 26252 80.91.229.3 (27 Apr 2016 07:56:42 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Wed, 27 Apr 2016 07:56:42 +0000 (UTC) To: musl@lists.openwall.com Original-X-From: musl-return-9971-gllmg-musl=m.gmane.org@lists.openwall.com Wed Apr 27 09:56:42 2016 Return-path: Envelope-to: gllmg-musl@m.gmane.org Original-Received: from mother.openwall.net ([195.42.179.200]) by plane.gmane.org with smtp (Exim 4.69) (envelope-from ) id 1avKKt-0000Hq-6s for gllmg-musl@m.gmane.org; Wed, 27 Apr 2016 09:56:39 +0200 Original-Received: (qmail 30097 invoked by uid 550); 27 Apr 2016 07:56:37 -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 30079 invoked from network); 27 Apr 2016 07:56:36 -0000 In-Reply-To: <20160426221815.GA24105@brightrain.aerifal.cx> User-Agent: Alpine 2.20 (LNX 67 2015-01-07) Xref: news.gmane.org gmane.linux.lib.musl.general:9958 Archived-At: On Tue, 26 Apr 2016, Rich Felker wrote: > There's a lot of nonsense-UB in stdio due to buffer comparisons along > the lines of "f->rpos < f->rend". The intent of these comparisons is > to simultaneously check that the buffer is initialized for the proper > mode (read or write) and that there's data left in it (for reading) or > space left (to write) or buffered data to be written out (for write), > etc. > > Unfortunately, when the buffer is uninitialized for the mode being > checked, the comparison becomes NULL obviously be false (since < implies !=), NULL [snip] > So what to do? Well, since NULL-NULL and NULL I think a good place to start might be coming up with and documenting a > clear model for how stdio's buffer internals are supposed to work, what > operations are allowed, what invariants hold, etc. based on the above > analysis of current UB issues and what the code is doing. would be nice to have; you recently noted that setvbuf has restrictions, and if there are other non-obvious stuff (especially if musl-specific), having it written down should be useful. Thanks. Alexander