From: <lihua.zhao.cn@windriver.com>
To: <musl@lists.openwall.com>
Cc: <lihua.zhao.cn@windriver.com>
Subject: [musl] [PATCH v2] mman: correct length check in __shm_mapname
Date: Tue, 5 Nov 2024 12:56:28 +0800 [thread overview]
Message-ID: <20241105045628.1542264-1-lihua.zhao.cn@windriver.com> (raw)
In-Reply-To: <20241105030058.GF10433@brightrain.aerifal.cx>
From: Lihua Zhao <lihua.zhao.cn@windriver.com>
account for leading slashes when comparing against NAME_MAX.
Signed-off-by: Lihua Zhao <lihua.zhao.cn@windriver.com>
---
According to https://pubs.opengroup.org/onlinepubs/9799919799/:
leading <slash> character in name is implementation-defined, and that the length limits for the name argument are implementation-defined and need not be the same as the pathname limits {PATH_MAX} and {NAME_MAX}.
Although it is implementation-defined, glibc obviously calculates the lead slash.
src/mman/shm_open.c | 12 ++++++------
1 file changed, 6 insertions(+), 6 deletions(-)
diff --git a/src/mman/shm_open.c b/src/mman/shm_open.c
index 79784bd3..07dbeb96 100644
--- a/src/mman/shm_open.c
+++ b/src/mman/shm_open.c
@@ -8,19 +8,19 @@
char *__shm_mapname(const char *name, char *buf)
{
- char *p;
- while (*name == '/') name++;
- if (*(p = __strchrnul(name, '/')) || p==name ||
- (p-name <= 2 && name[0]=='.' && p[-1]=='.')) {
+ const char *s=name, *e;
+ while (*s == '/') s++;
+ if (*(e = __strchrnul(s, '/')) || e==s ||
+ (e-s <= 2 && s[0]=='.' && e[-1]=='.')) {
errno = EINVAL;
return 0;
}
- if (p-name > NAME_MAX) {
+ if (e-name > NAME_MAX) {
errno = ENAMETOOLONG;
return 0;
}
memcpy(buf, "/dev/shm/", 9);
- memcpy(buf+9, name, p-name+1);
+ memcpy(buf+9, s, e-s+1);
return buf;
}
--
2.34.1
next prev parent reply other threads:[~2024-11-05 4:56 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-11-05 1:06 [musl] [PATCH] " lihua.zhao.cn
2024-11-05 1:46 ` Rich Felker
2024-11-05 2:03 ` Zhao, Lihua (CN)
2024-11-05 3:00 ` Rich Felker
2024-11-05 4:56 ` lihua.zhao.cn [this message]
2024-11-05 5:15 ` [musl] [PATCH v2] " Rich Felker
2024-11-05 6:06 ` Zhao, Lihua (CN)
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=20241105045628.1542264-1-lihua.zhao.cn@windriver.com \
--to=lihua.zhao.cn@windriver.com \
--cc=musl@lists.openwall.com \
/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.
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/musl/
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 NNTP newsgroup(s).