From: "Érico Nogueira" <ericonr@disroot.org>
To: musl@lists.openwall.com
Cc: "Érico Nogueira" <ericonr@disroot.org>,
"Michael Forney" <mforney@mforney.org>
Subject: [musl] [PATCH 1/2] fix error checking in pthread_getname_np
Date: Sat, 10 Jul 2021 00:24:59 -0300 [thread overview]
Message-ID: <20210710032500.9249-1-ericonr@disroot.org> (raw)
len is unsigned and can never be smaller than 0. though unlikely, an
error in read() would have lead to an out of bounds write to name.
Reported-by: Michael Forney <mforney@mforney.org>
---
src/thread/pthread_getname_np.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/thread/pthread_getname_np.c b/src/thread/pthread_getname_np.c
index 48d1a294..85504e45 100644
--- a/src/thread/pthread_getname_np.c
+++ b/src/thread/pthread_getname_np.c
@@ -17,7 +17,7 @@ int pthread_getname_np(pthread_t thread, char *name, size_t len)
snprintf(f, sizeof f, "/proc/self/task/%d/comm", thread->tid);
pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &cs);
- if ((fd = open(f, O_RDONLY|O_CLOEXEC)) < 0 || (len = read(fd, name, len)) < 0) status = errno;
+ if ((fd = open(f, O_RDONLY|O_CLOEXEC)) < 0 || (len = read(fd, name, len)) == -1) status = errno;
else name[len-1] = 0; /* remove trailing new line only if successful */
if (fd >= 0) close(fd);
pthread_setcancelstate(cs, 0);
--
2.32.0
next reply other threads:[~2021-07-10 3:25 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-07-10 3:24 Érico Nogueira [this message]
2021-07-10 3:25 ` [musl] [PATCH 2/2] add -Wtype-limits to enabled warning list Érico Nogueira
2021-07-10 17:00 ` Rich Felker
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=20210710032500.9249-1-ericonr@disroot.org \
--to=ericonr@disroot.org \
--cc=mforney@mforney.org \
--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).