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,WEIRD_QUOTING autolearn=ham autolearn_force=no version=3.4.4 Received: (qmail 19844 invoked from network); 24 Feb 2023 15:13:44 -0000 Received: from second.openwall.net (193.110.157.125) by inbox.vuxu.org with ESMTPUTF8; 24 Feb 2023 15:13:44 -0000 Received: (qmail 5295 invoked by uid 550); 24 Feb 2023 15:13:41 -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 5256 invoked from network); 24 Feb 2023 15:13:40 -0000 X-Virus-Scanned: SPAM Filter at disroot.org Date: Fri, 24 Feb 2023 21:13:34 +0600 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=disroot.org; s=mail; t=1677251608; bh=nkbbrCzYoMmBa1SU+QHbrAQyWOnOSbnbYXRryTUOMp4=; h=Date:From:To:Cc:Subject:References:In-Reply-To; b=Lqqz0QvKEDJFsGEr8aiLLcreStH0W4WbojGBXct+lfn3UCP7RtfTACx6tGCmrzNsu wIVoN1Y7iQlC1eOwSk6FpO5mESMyTaLlDTTIiK9Et/zsnnotgEfGr+qj0YhZbDQFah UMvGLnPQ8r2c/GlXFQsUTGAn7m/b9tnmRxXoE31C1y37LKt0oiruDsc53pjpr6W1VX AUTqg3kR28wwu6FyxgcPduQQ0EKBrK79UBGlK1AeeN6J642ba2ARFyypVBUXZDJHIF /IQWsnkmkFSIJ5Ze1mPlnd35MVJipGMyDPBAOiOtpeiYZowSTuaexMCrAq5GL5GUFk yLVFD3+fo6Bdg== From: NRK To: Tamir Duberstein Cc: Rich Felker , musl@lists.openwall.com Message-ID: <20230224151334.ycgddzdc4o5a4m5q@gen2.localdomain> References: <20230224133413.GE4163@brightrain.aerifal.cx> <20230224135511.iunglqtcvpjeqgtv@gen2.localdomain> <20230224140739.GF4163@brightrain.aerifal.cx> <20230224141731.dm4w7fbfkczbx42e@gen2.localdomain> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Subject: Re: [musl] undefined behavior in fread.c On Fri, Feb 24, 2023 at 09:42:00AM -0500, Tamir Duberstein wrote: > We could take the lock and still avoid UB with an early return. As Jens has pointed out, the UB in this case is the caller calling fread with NULL - not in musl. And on a sidenote, I've always found - especially for the various mem* functions - accepting 0 size but not accepting NULL arg (when n is 0) to be a poor choice. A lot of the value that accepting 0 size provides is diminished by not accepting NULL. And this affects more than just libc, too. Compilers like gcc/clang will see a call like `memcmp(p, q, 0)` and will ""determine"" `p` and `q` are non-null (which can lead to deleting any subsequent null-checks on those pointers). But anyways, that was just a small rant. As things currently are, *even if* musl deal with the NULL pointer - any caller calling fread with NULL is still in danger from compilers and needs to fix it on their side. - NRK