From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.org/gmane.linux.lib.musl.general/12518 Path: news.gmane.org!.POSTED!not-for-mail From: Szabolcs Nagy Newsgroups: gmane.linux.lib.musl.general Subject: Re: fwrite() - possible division by zero Date: Wed, 14 Feb 2018 22:15:23 +0100 Message-ID: <20180214211523.GC4418@port70.net> References: <20180214193942.nar6nvuulv4rg5nt@voyager> <20180214200707.hvbwbn733gwvtkbq@voyager> Reply-To: musl@lists.openwall.com NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: blaine.gmane.org 1518642838 25612 195.159.176.226 (14 Feb 2018 21:13:58 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Wed, 14 Feb 2018 21:13:58 +0000 (UTC) User-Agent: Mutt/1.9.1 (2017-09-22) To: musl@lists.openwall.com Original-X-From: musl-return-12535-gllmg-musl=m.gmane.org@lists.openwall.com Wed Feb 14 22:13:53 2018 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 1em4Mu-0005CG-QQ for gllmg-musl@m.gmane.org; Wed, 14 Feb 2018 22:13:32 +0100 Original-Received: (qmail 9462 invoked by uid 550); 14 Feb 2018 21:15:36 -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 9444 invoked from network); 14 Feb 2018 21:15:35 -0000 Mail-Followup-To: musl@lists.openwall.com Content-Disposition: inline In-Reply-To: Xref: news.gmane.org gmane.linux.lib.musl.general:12518 Archived-At: * Andrew Bell [2018-02-14 15:11:34 -0500]: > On Wed, Feb 14, 2018 at 3:07 PM, Markus Wichmann wrote: > > > On Wed, Feb 14, 2018 at 02:48:14PM -0500, Andrew Bell wrote: > > > Why not early return if size == 0 and avoid the call to __fwritex > > > altogether? > > > > > > > Because it's a rare corner case? Here, there's also locking correctness > > to consider: fwrite() has to block until f is unlocked, irrespective of > > parameters. So there's no real benefit to doing an early return. > > > > But it's already being checked to set nmemb to 0. Couldn't you just return > 0 and avoid the lock as well? the lock must not be avoided. otherwise fwrite would make progress on a FILE locked by another thread which is non-conforming. the code looks perfectly fine to me.