summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorA. Wilcox <awilcox@wilcox-tech.com>2019-02-19 03:34:53 +0000
committerA. Wilcox <awilcox@wilcox-tech.com>2019-02-19 03:34:53 +0000
commit6d13380e242a8b2e72460080070b263c54ce3d4d (patch)
treea5ac12b7e1d2accd3632198384d341358b5295b3
parent70add83428603fe757098a9531a22e611a759017 (diff)
parent40e85cf9ed75982d65182039a2aa22436a3469ee (diff)
downloadgcompat-6d13380e242a8b2e72460080070b263c54ce3d4d.tar.gz
gcompat-6d13380e242a8b2e72460080070b263c54ce3d4d.tar.bz2
gcompat-6d13380e242a8b2e72460080070b263c54ce3d4d.tar.xz
gcompat-6d13380e242a8b2e72460080070b263c54ce3d4d.zip
Merge branch 'patch-5' into 'master'
pthread: Fix pthread_getname_np Remove the trailing newline, and ensure the string returned is always null-terminated. Signed-off-by: Samuel Holland <samuel@sholland.org> See merge request !5
-rw-r--r--libgcompat/pthread.c10
1 files changed, 6 insertions, 4 deletions
diff --git a/libgcompat/pthread.c b/libgcompat/pthread.c
index 0456c40..f15e9f1 100644
--- a/libgcompat/pthread.c
+++ b/libgcompat/pthread.c
@@ -38,15 +38,17 @@ weak_alias(__register_atfork, register_atfork);
int pthread_getname_np(pthread_t thread, char *name, size_t len)
{
int fd = open("/proc/thread-self/comm", O_RDONLY | O_CLOEXEC);
- char dummy;
+ ssize_t n;
if (fd < 0)
return errno;
- if (read(fd, name, len) < 0)
+ n = read(fd, name, len);
+ if (n < 0)
return errno;
- /* If there's more to read, the buffer was too small. */
- if (read(fd, &dummy, 1) > 0)
+ /* If the trailing newline was not read, the buffer was too small. */
+ if (n == 0 || name[n - 1] != '\n')
return ERANGE;
+ name[n - 1] = '\0';
return 0;
}