From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=-1.1 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_MSPIKE_H2 autolearn=ham autolearn_force=no version=3.4.4 Received: (qmail 10852 invoked from network); 24 Feb 2023 13:55:31 -0000 Received: from second.openwall.net (193.110.157.125) by inbox.vuxu.org with ESMTPUTF8; 24 Feb 2023 13:55:31 -0000 Received: (qmail 30400 invoked by uid 550); 24 Feb 2023 13:55:29 -0000 Mailing-List: contact musl-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-ID: Reply-To: musl@lists.openwall.com Received: (qmail 30362 invoked from network); 24 Feb 2023 13:55:28 -0000 X-Virus-Scanned: SPAM Filter at disroot.org Date: Fri, 24 Feb 2023 19:55:11 +0600 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=disroot.org; s=mail; t=1677246916; bh=ySNxkHrWYYEC6GKMe2S7HJ8RXV/3IFmqBFxGlTBXPnU=; h=Date:From:To:Cc:Subject:References:In-Reply-To; b=HSuE1Qib+ITUxXQ4uCeXcweH0O084omH45xYKH65rpa+C37Jpv6JLTcZzy4MOd4w9 g8PxwOR5QXuWnHlonqMXJuUSOmeAI1pumPPOinLGi3iZ2lyX41e8ZiQ3AumovT3ceJ +lxnLQ2h58rgBdB+cTCoWnqd9tggI0BDi3t89eTUblG3l+DTNII5FPWrror0OfB3sy ypPfGVyZnvaPZHuL8Q19SK1KXKXfrUcYQO6TPzfxdgea+doIXaUjmPl1wdEFIrC3YF ZTEL/STT0BKNmcqFy++6IHKjOwIp+Sw45KeBiId3AdywJ3GkmU7qvu3fxFV6xV6Ea0 bj8C0wjUfNHTw== From: NRK To: musl@lists.openwall.com Cc: Tamir Duberstein Message-ID: <20230224135511.iunglqtcvpjeqgtv@gen2.localdomain> References: <20230224133413.GE4163@brightrain.aerifal.cx> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20230224133413.GE4163@brightrain.aerifal.cx> Subject: Re: [musl] undefined behavior in fread.c On Fri, Feb 24, 2023 at 08:34:14AM -0500, Rich Felker wrote: > Is there any indication that passing NULL as the first argument to > fread is not itself undefined? C99 says the following: | If size or nmemb is zero, fread returns zero and the contents of the | array and the state of the stream remain unchanged. It doesn't explicitly mention weather stream can be NULL or not in case of 0 size/nmemb - but regardless, is there any actual reason for not returning early? The following should be OK as far as I see: - if (!size) nmemb = 0; + if (!size || !nmemb) return 0; or `if (!len) return 0;` could also work if multiplication overflow is not a concern. - NRK