summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorÉrico Nogueira <ericonr@disroot.org>2021-07-10 00:24:59 -0300
committerRich Felker <dalias@aerifal.cx>2021-08-06 11:26:15 -0400
commit3eed6a6f0a400763313bc5dca6e3b22a75166dbe (patch)
tree65c107bccdadc07a07db7fb4d8e7bd3b75f92774
parent3f701faace7addc75d16dea8a6cd769fa5b3f260 (diff)
downloadmusl-3eed6a6f0a400763313bc5dca6e3b22a75166dbe.tar.gz
fix error checking in pthread_getname_np
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>
-rw-r--r--src/thread/pthread_getname_np.c2
1 files changed, 1 insertions, 1 deletions
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);