From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from xry111.site (xry111.site [IPv6:2001:470:683e::1]) by sourceware.org (Postfix) with ESMTPS id 5A2F43857400 for ; Tue, 7 Mar 2023 08:54:37 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 5A2F43857400 Authentication-Results: sourceware.org; dmarc=pass (p=reject dis=none) header.from=xry111.site Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=xry111.site DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=xry111.site; s=default; t=1678179275; bh=GpYneSE650t8gW486P5WVAfKf/D3iw4Vn8OYLALnEpg=; h=Subject:From:To:Date:In-Reply-To:References:From; b=WQjwYL4XP3xb5IjQ0H+ENkBTMqPUhZCIEJdNJ1IqLeqMX8w6RU9/aiOHoaHM6sO33 xuQ19yEX2HWjyHl2pBm+kW7nNSzHK+4bnkMYbG1I0lfDM6XIoQoD0mGY3aeOY3jYPS 3AGbEd3UO3DPvRUPR+IWRv9bSdsv4/fDLfJiAqbQ= Received: from [IPv6:240e:457:1130:24c0:882b:64fc:f6e9:11b3] (unknown [IPv6:240e:457:1130:24c0:882b:64fc:f6e9:11b3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature ECDSA (P-384) server-digest SHA384) (Client did not present a certificate) (Authenticated sender: xry111@xry111.site) by xry111.site (Postfix) with ESMTPSA id 0640065AE7; Tue, 7 Mar 2023 03:54:29 -0500 (EST) Message-ID: <2ff8bc971b5244496b02ebc99ef623532a1a787b.camel@xry111.site> Subject: Re: [PATCH] rt: fix shm_open not set ENAMETOOLONG when name exceeds {_POSIX_PATH_MAX} From: Xi Ruoyao To: abushwang , libc-alpha@sourceware.org, carlos@redhat.com Date: Tue, 07 Mar 2023 16:54:20 +0800 In-Reply-To: <20230307083229.629411-1-abushwangs@gmail.com> References: <20230307083229.629411-1-abushwangs@gmail.com> Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable User-Agent: Evolution 3.46.4 MIME-Version: 1.0 X-Spam-Status: No, score=-0.2 required=5.0 tests=BAYES_00,BODY_8BITS,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,LIKELY_SPAM_FROM,SPF_HELO_PASS,SPF_PASS,TXREP autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: On Tue, 2023-03-07 at 16:32 +0800, abushwang via Libc-alpha wrote: > according to man-pages-posix-2017, shm_open() function may fail if the le= ngth > of the name argument exceeds {_POSIX_PATH_MAX} and set ENAMETOOLONG It's "may" fail, not "shall" fail. POSIX 2017 says "may" means: may Describes a feature or behavior that is optional for an implementation that conforms to POSIX.1-2017. An application should not rely on the existence of the feature or behavior. An application that relies on such a feature or behavior cannot be assured to be portable across conforming implementations. We should not break existing programs just for a "may" clause. /* snip */ > =C2=A0int > =C2=A0__shm_get_name (struct shmdir_name *result, const char *name, bool > sem_prefix) > @@ -50,13 +51,15 @@ __shm_get_name (struct shmdir_name *result, const > char *name, bool sem_prefix) > =C2=A0=C2=A0 while (name[0] =3D=3D '/') > =C2=A0=C2=A0=C2=A0=C2=A0 ++name; > =C2=A0=C2=A0 namelen =3D strlen (name); > +=C2=A0 if (namelen > NAME_MAX) > +=C2=A0=C2=A0=C2=A0 return ENAMETOOLONG; > =C2=A0 > =C2=A0=C2=A0 if (sem_prefix) > =C2=A0=C2=A0=C2=A0=C2=A0 alloc_buffer_copy_bytes (&buffer, "sem.", strlen= ("sem.")); > =C2=A0=C2=A0 alloc_buffer_copy_bytes (&buffer, name, namelen + 1); > =C2=A0=C2=A0 if (namelen =3D=3D 0 || memchr (name, '/', namelen) !=3D NUL= L > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 || alloc_buffer_has_failed (&buffer)= ) If you really want ENAMETOOLONG I guess you can check if namelen > NAME_MAX here (as a very long namelen would have caused an allocation failure). By the way if namelen <=3D NAME_MAX but alloc_buffer_has_failed (due to a high memory usage) should we say ENOSPC instead of EINVAL? POSIX 2017 says: [ENOSPC] There is insufficient space for the creation of the new shared memory objec= t. > -=C2=A0=C2=A0=C2=A0 return -1; > +=C2=A0=C2=A0=C2=A0 return EINVAL; > =C2=A0=C2=A0 return 0; > =C2=A0} --=20 Xi Ruoyao School of Aerospace Science and Technology, Xidian University