public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
From: abush wang <abushwangs@gmail.com>
To: Xi Ruoyao <xry111@xry111.site>
Cc: libc-alpha@sourceware.org, carlos@redhat.com
Subject: Re: [PATCH] rt: fix shm_open not set ENAMETOOLONG when name exceeds {_POSIX_PATH_MAX}
Date: Tue, 7 Mar 2023 17:46:16 +0800	[thread overview]
Message-ID: <CAMLoAPY3iiHEWCWH9XWPSTJK1ENkpNxyo8-oYa2mEf9Bu3zShw@mail.gmail.com> (raw)
In-Reply-To: <CAMLoAPYVpV9LGtsfkeO4_CinvzFdBXUufY=aGfH8rzUGxpucUQ@mail.gmail.com>

[-- Attachment #1: Type: text/plain, Size: 2389 bytes --]

ENOSPC mean insufficient shared memory object, alloc_buffer_has_failed mean
insufficient memory for name, maybe they are different.

abush wang <abushwangs@gmail.com> 于2023年3月7日周二 17:46写道:

> I have re-send this patch according to your suggest.
>
> Thinks
> abushwang
>
> Xi Ruoyao <xry111@xry111.site> 于2023年3月7日周二 16:54写道:
>
>> 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] == '/')
>> >      ++name;
>> >    namelen = 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 == 0 || memchr (name, '/', namelen) != 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 <= 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 <xry111@xry111.site>
>> School of Aerospace Science and Technology, Xidian University
>>
>

  reply	other threads:[~2023-03-07  9:46 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-03-07  8:32 abushwang
2023-03-07  8:54 ` Xi Ruoyao
2023-03-07  9:46   ` abush wang
2023-03-07  9:46     ` abush wang [this message]
2023-03-07  9:45 abushwang
2023-03-07 10:02 ` Xi Ruoyao

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CAMLoAPY3iiHEWCWH9XWPSTJK1ENkpNxyo8-oYa2mEf9Bu3zShw@mail.gmail.com \
    --to=abushwangs@gmail.com \
    --cc=carlos@redhat.com \
    --cc=libc-alpha@sourceware.org \
    --cc=xry111@xry111.site \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).