From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-yw1-x1131.google.com (mail-yw1-x1131.google.com [IPv6:2607:f8b0:4864:20::1131]) by sourceware.org (Postfix) with ESMTPS id DE53D385B511 for ; Tue, 7 Mar 2023 09:46:28 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org DE53D385B511 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-yw1-x1131.google.com with SMTP id 00721157ae682-536c02c9dfbso234238177b3.11 for ; Tue, 07 Mar 2023 01:46:28 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; t=1678182388; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=/LWMGF9SylKGggoH3JieTPJp6m6OD5E1RwZEWaEoWjk=; b=GrnADmb+6xBg9FbpqatLN+WHqJApkGYD3DzprvKAM0ncMTXThvapoZgpTHfsnACKT8 TM1WZIybK+Idi1PkVdwVn6qetEwj7rx1XMIrNSwTycKl9A8MdTLLsnRlhh6QhshIHnOl 7cSzo7Lc6hSH5AS4jrKBoH3kdBC9yXt0CsZidbdfyw9PhBbJckIxKrSlwzTbj3sdVozU BuGJdxuCuvSAkeVKT/Ed9e9w5rorp4zhX+Kb03NHG8GRupMHM7JIahidY1nG+CKA1JAp BYLrgEzg5R/8K8DVqdwMpUlAYF2ddG4XFjCInasm00+yySlx+gmTTsHAWmWcnJx0QNZi AaIw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1678182388; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=/LWMGF9SylKGggoH3JieTPJp6m6OD5E1RwZEWaEoWjk=; b=rw2BwzYf1YpAC9m9znaVilVYRRbYIx2ktBoGmBIPp/hv7hXIfxUJwM1YrR9n8gH1KC 8ExQCBX/WnjT7wZ5mGmuwxbXIQHjlt7f89aSyF/LDCSdhKaALbmNJ+OiZJBsNz54Yepf Qn0++JZFdTgWvPSOWBN8mmrWJseZdeQNa2CN/9V4s0Odg4zvSdtYYdRiiMeOJ7Fe3bM6 ZXvT2moHEgvAhgI4NgoXjvgMFA9luj4VnTPaSMo3Ex2ieZsmIzWO/axcK8+gC+zd6mO6 KadxofebgX2voe85rVaRPvKpKJ8OwZVADsBpRZ79x7ZuVOvSseBa0lVwqbAS3vMmEVtL KzdQ== X-Gm-Message-State: AO0yUKVLVLXdoYcKLqv1V5jyh1b/Ee2jzPRMHmlzHHYPhEgLCxmZb3AT bEC15wFpJhrvNPvWXzZ7h4nNyOl32JcD1/ttz44= X-Google-Smtp-Source: AK7set9DGoJ/oLaDm9Ha5XKGqH3LhjqJoPfHAyAHv+CqxnftXdgzJdsaOfL+msrFFLWE9wsxUHVVagqrTZHuoD4Aq6s= X-Received: by 2002:a81:ad5a:0:b0:536:4d58:54b2 with SMTP id l26-20020a81ad5a000000b005364d5854b2mr9155398ywk.4.1678182388634; Tue, 07 Mar 2023 01:46:28 -0800 (PST) MIME-Version: 1.0 References: <20230307083229.629411-1-abushwangs@gmail.com> <2ff8bc971b5244496b02ebc99ef623532a1a787b.camel@xry111.site> In-Reply-To: From: abush wang Date: Tue, 7 Mar 2023 17:46:16 +0800 Message-ID: Subject: Re: [PATCH] rt: fix shm_open not set ENAMETOOLONG when name exceeds {_POSIX_PATH_MAX} To: Xi Ruoyao Cc: libc-alpha@sourceware.org, carlos@redhat.com Content-Type: multipart/alternative; boundary="00000000000024997d05f64c491d" X-Spam-Status: No, score=-0.4 required=5.0 tests=BAYES_00,BODY_8BITS,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,HTML_MESSAGE,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: --00000000000024997d05f64c491d Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable ENOSPC mean insufficient shared memory object, alloc_buffer_has_failed mean insufficient memory for name, maybe they are different. abush wang =E4=BA=8E2023=E5=B9=B43=E6=9C=887=E6=97= =A5=E5=91=A8=E4=BA=8C 17:46=E5=86=99=E9=81=93=EF=BC=9A > I have re-send this patch according to your suggest. > > Thinks > abushwang > > Xi Ruoyao =E4=BA=8E2023=E5=B9=B43=E6=9C=887=E6=97=A5= =E5=91=A8=E4=BA=8C 16:54=E5=86=99=E9=81=93=EF=BC=9A > >> 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 >> length >> > 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 */ >> >> > int >> > __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) >> > while (name[0] =3D=3D '/') >> > ++name; >> > namelen =3D strlen (name); >> > + if (namelen > NAME_MAX) >> > + return ENAMETOOLONG; >> > >> > if (sem_prefix) >> > alloc_buffer_copy_bytes (&buffer, "sem.", strlen ("sem.")); >> > alloc_buffer_copy_bytes (&buffer, name, namelen + 1); >> > if (namelen =3D=3D 0 || memchr (name, '/', namelen) !=3D NULL >> > || 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 >> object. >> >> > - return -1; >> > + return EINVAL; >> > return 0; >> > } >> >> -- >> Xi Ruoyao >> School of Aerospace Science and Technology, Xidian University >> > --00000000000024997d05f64c491d--