Hide Forgot
Description of problem: pthread_setname_np(3) segfaults when NULL is passed as the second argument: #define _GNU_SOURCE #include <pthread.h> #include <stdio.h> #include <string.h> int main(void) { pthread_t thr = pthread_self (); int ret = pthread_setname_np (thr, NULL); printf ("pthread_setname_np: %s\n", strerror (ret)); return 0; } Backtrace (on x86_64): #0 __strlen_sse2 () at ../sysdeps/x86_64/strlen.S:32 #1 0x000000315ae10641 in pthread_setname_np (th=140737354036992, name=0x0) at ../nptl/sysdeps/unix/sysv/linux/pthread_setname.c:41 #2 0x00000000004007b5 in main () at test.c:23 Yes, pthread_setname_np warns that argument 2 cannot be NULL, but it still shouldn't segfault. pthread_getname_np (thr, NULL, 16) generates the same warning but returns EFAULT instead of segfaulting; I presume pthread_setname_np should do the same. Version-Release number of selected component: glibc-2.14.90-24.fc16.4.i686 glibc-2.14.90-24.fc16.4.x86_64 Additional info: Unfortunately these functions have yet to be documented.
Reported upstream. I don't see this as important enough to deviate from whatever upstream decides to do with this issue. If upstream fixes this bug, that fix will come into Fedora via the usual process for updating glibc from the upstream sources.
Why it shouldn't segfault? If you call memcpy with NULL, it will segfault too. The distinction between EFAULT and segfaulting is just on what is implemented as a syscall and what is not.
(In reply to comment #2) > Why it shouldn't segfault? If you call memcpy with NULL, it will segfault too. > The distinction between EFAULT and segfaulting is just on what is implemented > as a syscall and what is not. As noted in comment 0, pthread_getname_np(thr, NULL, 16) returns EFAULT but pthread_setname_np (thr, NULL) segfaults. As matching functions, I would expect them to be consistent.
When it isn't documented in man pages or info pages, the headers are the only documentation. And the headers clearly document that you must not call it with NULL: /* Get thread name visible in the kernel and its interfaces. */ extern int pthread_getname_np (pthread_t __target_thread, char *__buf, size_t __buflen) __THROW __nonnull ((2)); /* Set thread name visible in the kernel and its interfaces. */ extern int pthread_setname_np (pthread_t __target_thread, __const char *__name) __THROW __nonnull ((2)); So you shouldn't be trying that, that is undefined behavior, anything can happen.