From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 124426 invoked by alias); 30 Oct 2019 18:36:48 -0000 Mailing-List: contact libc-alpha-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: libc-alpha-owner@sourceware.org Received: (qmail 123741 invoked by uid 89); 30 Oct 2019 18:36:47 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-2.8 required=5.0 tests=AWL,BAYES_00,SPF_PASS autolearn=ham version=3.3.1 spammy=comparable, H*f:sk:exm6CvC, H*i:sk:exm6CvC, H*i:CAKCAbMjW3YZa3 X-HELO: albireo.enyo.de From: Florian Weimer To: Zack Weinberg Cc: Andreas Schwab , GNU C Library Subject: Re: [review] manual: Clarify strnlen, wcsnlen, strndup null termination behavior References: <87a79i33kt.fsf@oldenburg2.str.redhat.com> <875zk6337v.fsf@oldenburg2.str.redhat.com> <877e4muoti.fsf@igel.home> Date: Wed, 30 Oct 2019 18:36:00 -0000 In-Reply-To: (Zack Weinberg's message of "Wed, 30 Oct 2019 14:12:26 -0400") Message-ID: <87zhhikrly.fsf@mid.deneb.enyo.de> MIME-Version: 1.0 Content-Type: text/plain X-SW-Source: 2019-10/txt/msg00939.txt.bz2 * Zack Weinberg: > On Wed, Oct 30, 2019 at 1:26 PM Andreas Schwab wrote: >> On Okt 30 2019, Zack Weinberg wrote: >> >> > Yes, that could be a defect in the specification of strncpy (I can >> > argue either way about what the parenthetical "(bytes that follow a >> > NUL character are not copied)" means). How does text's presence or >> > absence in the specification of strncpy change anything about the >> > requirements on strnlen? >> >> Because it shows how flawed your argument is. > > Are you seriously saying that I have to read the specification of > strncpy to understand the specification of strnlen? That's not how I > was taught to read standards. I actually find the strncpy-based argument quite convincing. And it's really the way you have to read standards if you want derive meaning from them. You need to look at how certain terms are used in other contexts and what they apply there. For strncpy, clearly the intent is that it is safe to specify a source string shorter than the target array. If comparable wording is used to describe the strnlen behavior, then it makes sense to assume that the POSIX authors probably have not thought about this corner case. At the very least, it tells us that the standard does not say what the behavior should be in this case. Does anyone know if we have test cases that exercise page crossing after the null terminator in strnlen?