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 18:02:02 +0800	[thread overview]
Message-ID: <04d31136b4039397220b6e1b1afe0a8bd89bce1c.camel@xry111.site> (raw)
In-Reply-To: <20230307094546.633473-1-abushwangs@gmail.com>

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 length
> of the name argument exceeds {_POSIX_PATH_MAX} and set ENAMETOOLONG
> 
> Signed-off-by: abushwang <abushwangs@gmail.com>

Please use [PATCH v2] or v3, v4, ... into the title when you update the patch.

/* snip */

>  int
>  __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)
>    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
> +  if (namelen == 0 || namelen > NAME_MAX || memchr (name, '/', namelen) != 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. 

I was not telling you to make the code more compact.

-- 
Xi Ruoyao <xry111@xry111.site>
School of Aerospace Science and Technology, Xidian University

  reply	other threads:[~2023-03-07 10:02 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-03-07  9:45 abushwang
2023-03-07 10:02 ` Xi Ruoyao [this message]
  -- strict thread matches above, loose matches on Subject: below --
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

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=04d31136b4039397220b6e1b1afe0a8bd89bce1c.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).