From: abushwang <abushwangs@gmail.com>
To: libc-alpha@sourceware.org, carlos@redhat.com
Cc: abushwang <abushwangs@gmail.com>
Subject: [PATCH] rt: fix shm_open not set ENAMETOOLONG when name exceeds {_POSIX_PATH_MAX}
Date: Tue, 7 Mar 2023 17:45:46 +0800 [thread overview]
Message-ID: <20230307094546.633473-1-abushwangs@gmail.com> (raw)
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>
---
posix/shm-directory.c | 5 +++--
rt/shm_open.c | 5 +++--
2 files changed, 6 insertions(+), 4 deletions(-)
diff --git a/posix/shm-directory.c b/posix/shm-directory.c
index 86d9fd8e4f..ca9d9f2f77 100644
--- a/posix/shm-directory.c
+++ b/posix/shm-directory.c
@@ -25,6 +25,7 @@
#include <string.h>
#include <sys/mman.h>
#include <fcntl.h>
+#include <errno.h>
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
|| alloc_buffer_has_failed (&buffer))
- return -1;
+ return namelen ? ENAMETOOLONG : EINVAL;
return 0;
}
libc_hidden_def (__shm_get_name)
diff --git a/rt/shm_open.c b/rt/shm_open.c
index 6c1f4d604f..fc1dc96bb4 100644
--- a/rt/shm_open.c
+++ b/rt/shm_open.c
@@ -30,9 +30,10 @@ int
__shm_open (const char *name, int oflag, mode_t mode)
{
struct shmdir_name dirname;
- if (__shm_get_name (&dirname, name, false) != 0)
+ int ret =__shm_get_name (&dirname, name, false);
+ if (ret != 0)
{
- __set_errno (EINVAL);
+ __set_errno (ret);
return -1;
}
--
2.36.1
next reply other threads:[~2023-03-07 9:45 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-03-07 9:45 abushwang [this message]
2023-03-07 10:02 ` Xi Ruoyao
-- 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=20230307094546.633473-1-abushwangs@gmail.com \
--to=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).