fix: pthread_setname_np fails on longer tread names
authorMichael Jeanson <mjeanson@efficios.com>
Fri, 16 Oct 2020 19:44:36 +0000 (15:44 -0400)
committerMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Fri, 16 Oct 2020 20:28:02 +0000 (16:28 -0400)
When supplied with a thread name of more than 16 bytes including the
null terminating byte pthread_setname_np will fail with ERANGE,
replicate this behavior in the compat wrappers.

Change-Id: I91ac35a400a39c297e49fcab83b4f345b7ad92d0
Signed-off-by: Michael Jeanson <mjeanson@efficios.com>
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
liblttng-ust/compat.h

index 69761880e125fbff0504320697c22203180b7d97..a941b9a1ed407a945ecef8d624ed2b98f9f5387a 100644 (file)
@@ -23,6 +23,7 @@
 
 #include <pthread.h>
 #include <errno.h>
+#include <string.h>
 
 #include <lttng/ust-abi.h>
 
@@ -59,6 +60,11 @@ int lttng_pthread_getname_np(char *name, size_t len)
 static inline
 int lttng_pthread_setname_np(const char *name)
 {
+       /* Replicate pthread_setname_np's behavior */
+       if (strnlen(name, LTTNG_UST_ABI_PROCNAME_LEN) >= LTTNG_UST_ABI_PROCNAME_LEN) {
+               return ERANGE;
+       }
+
        pthread_set_name_np(pthread_self(), name);
        return 0;
 }
@@ -77,6 +83,10 @@ int lttng_pthread_getname_np(char *name, size_t len)
 static inline
 int lttng_pthread_setname_np(const char *name)
 {
+       /* Replicate pthread_setname_np's behavior */
+       if (strnlen(name, LTTNG_UST_ABI_PROCNAME_LEN) >= LTTNG_UST_ABI_PROCNAME_LEN) {
+               return ERANGE;
+       }
        return prctl(PR_SET_NAME, name, 0, 0, 0);
 }
 
This page took 0.028747 seconds and 4 git commands to generate.