public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
From: Xi Ruoyao <xry111@xry111.site>
To: abushwang <abushwangs@gmail.com>,
	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, 07 Mar 2023 16:54:20 +0800	[thread overview]
Message-ID: <2ff8bc971b5244496b02ebc99ef623532a1a787b.camel@xry111.site> (raw)
In-Reply-To: <20230307083229.629411-1-abushwangs@gmail.com>

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  8:54 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 [this message]
2023-03-07  9:46   ` abush wang
2023-03-07  9:46     ` abush wang
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=2ff8bc971b5244496b02ebc99ef623532a1a787b.camel@xry111.site \
    --to=xry111@xry111.site \
    --cc=abushwangs@gmail.com \
    --cc=carlos@redhat.com \
    --cc=libc-alpha@sourceware.org \
    /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).