diff options
author | abushwang <abushwangs@gmail.com> | 2023-03-07 20:16:20 +0800 |
---|---|---|
committer | Adhemerval Zanella <adhemerval.zanella@linaro.org> | 2023-03-08 10:11:54 -0300 |
commit | 0b7bf0e0a486da6be7c5dde742a80c1138f9cc89 (patch) | |
tree | ecacffd3daf24ed95b374a8710e390a66723706b /posix | |
parent | 65387e48097077c71ed527457c59ba59f3a1f3ee (diff) | |
download | glibc-0b7bf0e0a486da6be7c5dde742a80c1138f9cc89.zip glibc-0b7bf0e0a486da6be7c5dde742a80c1138f9cc89.tar.gz glibc-0b7bf0e0a486da6be7c5dde742a80c1138f9cc89.tar.bz2 |
rt: fix shm_open not set ENAMETOOLONG when name exceeds {_POSIX_PATH_MAX}
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>
Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
Diffstat (limited to 'posix')
-rw-r--r-- | posix/shm-directory.c | 12 |
1 files changed, 9 insertions, 3 deletions
diff --git a/posix/shm-directory.c b/posix/shm-directory.c index 86d9fd8..f130bab 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,14 @@ __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 - || alloc_buffer_has_failed (&buffer)) - return -1; + if (namelen == 0 || memchr (name, '/', namelen) != NULL) + return EINVAL; + if (alloc_buffer_has_failed (&buffer)) + { + if (namelen > NAME_MAX) + return ENAMETOOLONG; + return EINVAL; + } return 0; } libc_hidden_def (__shm_get_name) |