mailing list of musl libc
 help / color / mirror / code / Atom feed
* [musl] [PATCH 1/2] fix error checking in pthread_getname_np
@ 2021-07-10  3:24 Érico Nogueira
  2021-07-10  3:25 ` [musl] [PATCH 2/2] add -Wtype-limits to enabled warning list Érico Nogueira
  0 siblings, 1 reply; 3+ messages in thread
From: Érico Nogueira @ 2021-07-10  3:24 UTC (permalink / raw)
  To: musl; +Cc: Érico Nogueira, Michael Forney

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


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2021-07-10 17:00 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-07-10  3:24 [musl] [PATCH 1/2] fix error checking in pthread_getname_np Érico Nogueira
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

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).