From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from xry111.site (xry111.site [89.208.246.23]) by sourceware.org (Postfix) with ESMTPS id BF04B3858C20 for ; Tue, 7 Mar 2023 10:02:14 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org BF04B3858C20 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=1678183334; bh=iYSwl9g/nGzUntSBBwKK87hJSrZmnJwQt0e5WDpwdak=; h=Subject:From:To:Date:In-Reply-To:References:From; b=ZnCuHrAG6DY0HJstTHOMU8gIle+ARYns8jow8+/1Xg9BefkxooUZkvMicR5GiLvEO WnwkGix1CTJUjRuOZqhVGJs/btHfYL/VjtborA+feb14lRAt+S4TedfI9s/hP17QdT hblOdzY9s3OwSvGbTFzqpokuwm2gDto02NxcZ6/Q= 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)) (Client did not present a certificate) (Authenticated sender: xry111@xry111.site) by xry111.site (Postfix) with ESMTPSA id D821465B14; Tue, 7 Mar 2023 05:02:09 -0500 (EST) Message-ID: <04d31136b4039397220b6e1b1afe0a8bd89bce1c.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 18:02:02 +0800 In-Reply-To: <20230307094546.633473-1-abushwangs@gmail.com> References: <20230307094546.633473-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.3 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 17:45 +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 >=20 > Signed-off-by: abushwang Please use [PATCH v2] or v3, v4, ... into the title when you update the pat= ch. /* snip */ > =C2=A0int > =C2=A0__shm_get_name (struct shmdir_name *result, const char *name, bool = sem_prefix) > @@ -54,9 +55,9 @@ __shm_get_name (struct shmdir_name *result, const char = *name, bool sem_prefix) > =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 if (namelen =3D=3D 0 || memchr (name, '/', namelen) !=3D NULL > +=C2=A0 if (namelen =3D=3D 0 || namelen > NAME_MAX || memchr (name, '/', = namelen) !=3D NULL You can't just reject any namelen > NAMEMAX because a "may" clause in the specification. You may only do that if the allocation fails. What you are doing is like: the specification of a capacitor says it may (not "must" or "shall"!) blow up if the temperature is > 90C, then you add a bomb into the capacitor which blows up when the temperature reaches 90C. It's definitely wrong.=20 I was not telling you to make the code more compact. --=20 Xi Ruoyao School of Aerospace Science and Technology, Xidian University