From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.org/gmane.linux.lib.musl.general/12517 Path: news.gmane.org!.POSTED!not-for-mail From: Andrew Bell Newsgroups: gmane.linux.lib.musl.general Subject: Re: fwrite() - possible division by zero Date: Wed, 14 Feb 2018 15:11:34 -0500 Message-ID: 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: multipart/alternative; boundary="94eb2c085146cf9759056531b7aa" X-Trace: blaine.gmane.org 1518639007 28296 195.159.176.226 (14 Feb 2018 20:10:07 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Wed, 14 Feb 2018 20:10:07 +0000 (UTC) To: musl@lists.openwall.com Original-X-From: musl-return-12534-gllmg-musl=m.gmane.org@lists.openwall.com Wed Feb 14 21:10:03 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 1em3NH-0006Pl-Lh for gllmg-musl@m.gmane.org; Wed, 14 Feb 2018 21:09:51 +0100 Original-Received: (qmail 14000 invoked by uid 550); 14 Feb 2018 20:11:47 -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 13977 invoked from network); 14 Feb 2018 20:11:47 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:in-reply-to:references:from:date:message-id:subject:to; bh=zh1MKPfe3wIYid9aWvhlHZ29haiDELkLrW6krio25hg=; b=LYX3B8wA4n1wuMMAXk9//WSBOl+CyXjPZjD4PhBfB9oBk8BOOhAWrDWM2ZjEzNjXDI XR4ZhQuQH2wHbzXw5jDO9JseUjWF9xyB+asj2zOPJVp54V5YUdxYxdJC7Q5TvwC5SVdM AAVqrkrn43vNN1ZR20nxKFJ8/SanLTwyMekX+ivDKVi3Znvb36QPNipDcb9Z616zZqIP vt8BTru4jbod2HC8kKa8EqK0hH8XzMELSS72rwPgQsunYHniCzhasItRVjMi1a7wBXvx HZFSvzApSI7SmEhDkmqfC9JVSagX4tCmkEK7Z1skkC4Bn0q2GRWUvIpWfm9tBEuYvjIh nrng== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to; bh=zh1MKPfe3wIYid9aWvhlHZ29haiDELkLrW6krio25hg=; b=GkWT/MrOWkiiqKoIvLL1Y/B+2LZgilp9HShnPqKOlnpfxn0Uhj+KZ0QuSLYHmr28Jj EgXLzHbxzlsA+JH0sN6zMUleN1OuMPDX8Rg+HM3hYCTnZNSCgKoIJXAlzMhceKENI4l3 ANGvcjzZEQsB3+iyyg604noSoyh5d7Q1NueL8HT/4zYYZXb9xnP/1vP0iasqOty4Z1NX KCB6tWCZyclIo7x60FLBD8Zkzaj3h0oiTm+yeOAjmsBhxPBR4TXVFHyM11A3A4Dy4upe zGl1NX2h8HKGrj5abYYuUHKIoAuTBQwPsYX6Hi0eQE+52G1nVL4hJhEiosuURncn2NbF gsIQ== X-Gm-Message-State: APf1xPBjwyJB1nh/yttv6cI1tagjrJc0E7osa3XpScwN5HwBxNiFP14j W9h3Vv7uNaU4cLQSTgYYCsI3f29UkvDs/bwoXyfc/Q== X-Google-Smtp-Source: AH8x225dqUt3EsEyrOlRkpjDt3dT1XpRMGS8CHKD9/v9d2eqZauUasoe4niNohNqEsoAKnAUIEUxhfV5VQbfunUBLyE= X-Received: by 10.55.142.71 with SMTP id q68mr428512qkd.40.1518639095190; Wed, 14 Feb 2018 12:11:35 -0800 (PST) In-Reply-To: <20180214200707.hvbwbn733gwvtkbq@voyager> Xref: news.gmane.org gmane.linux.lib.musl.general:12517 Archived-At: --94eb2c085146cf9759056531b7aa Content-Type: text/plain; charset="UTF-8" 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? -- Andrew Bell andrew.bell.ia@gmail.com --94eb2c085146cf9759056531b7aa Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
On W= ed, Feb 14, 2018 at 3:07 PM, Markus Wichmann <nullplan@gmx.net> wrote:
On Wed, Feb 1= 4, 2018 at 02:48:14PM -0500, Andrew Bell wrote:
> Why not early return if size =3D=3D 0 and avoid the call to __fwritex<= br> > 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 nme= mb to 0.=C2=A0 Couldn't you just return 0 and avoid the lock as well?

--
--94eb2c085146cf9759056531b7aa--