Public bug reported:

The simple program:

#include <signal.h>
int
main (int arcg, char *argv[])   
{
  pthread_kill((pthread_t)0,0);
  return 0;
}
 
Gets "Segmentation fault". The man page says it should return ESRCH. Looking at 
the eglibc-2.19 source I found:

In ./nptl/sysdeps/unix/sysv/linux/pthread_sigqueue.c
     27 
     29 int
     30 pthread_sigqueue (threadid, signo, value)
     31      pthread_t threadid;
     32      int signo;
     33      const union sigval value;
     34 {
     35 #ifdef __NR_rt_tgsigqueueinfo
     36   struct pthread *pd = (struct pthread *) threadid;
     37 
     38   /* Make sure the descriptor is valid.  */
     39   if (DEBUGGING_P && INVALID_TD_P (pd))
     40     /* Not a valid thread handle.  */
     41     return ESRCH;
     42 

and in ./nptl/sysdeps/unix/sysv/linux/pthread_kill.c
     27 int
     28 __pthread_kill (threadid, signo)
     29      pthread_t threadid;
     30      int signo;
     31 {
     32   struct pthread *pd = (struct pthread *) threadid;
     33 
     34   /* Make sure the descriptor is valid.  */
     35   if (DEBUGGING_P && INVALID_TD_P (pd))
     36     /* Not a valid thread handle.  */
     37     return ESRCH;
     38 

and in ./ports/sysdeps/unix/bsd/bsd4.4/kfreebsd/fbtl/pthread_kill.c
     27 int
     28 __pthread_kill (threadid, signo)
     29      pthread_t threadid;
     30      int signo;
     31 {
     32   struct pthread *pd = (struct pthread *) threadid;
     33 
     34   /* Make sure the descriptor is valid.  */
     35   if (DEBUGGING_P && INVALID_TD_P (pd))
     36     /* Not a valid thread handle.  */
     37     return ESRCH;
     38 

In all of these cases, the "DEBUGGING_P &&" causes the "INVALID_TD_P
(pd)" test to not be generated, since DEBUGGING_P is #defined as 0. We
need to do the test!

The Ubuntu man page for pthread_kill says:

If sig is 0, then no signal is sent, but error checking is still
performed; this can be used to check for the existence of a thread ID.

$ lsb_release -rd
Description:    Ubuntu 14.04.3 LTS
Release:        14.04
$ apt-cache policy libc6
libc6:
  Installed: 2.19-0ubuntu6.6
  Candidate: 2.19-0ubuntu6.6
  Version table:
 *** 2.19-0ubuntu6.6 0
        500 http://ca.archive.ubuntu.com/ubuntu/ trusty-updates/main amd64 
Packages
        500 http://security.ubuntu.com/ubuntu/ trusty-security/main amd64 
Packages
        100 /var/lib/dpkg/status
     2.19-0ubuntu6 0
        500 http://ca.archive.ubuntu.com/ubuntu/ trusty/main amd64 Packages

** Affects: glibc (Ubuntu)
     Importance: Undecided
         Status: New

-- 
You received this bug notification because you are a member of Ubuntu
Bugs, which is subscribed to Ubuntu.
https://bugs.launchpad.net/bugs/1485168

Title:
  pthread_kill(0,0) Segmentation fault rather than ESRCH

To manage notifications about this bug go to:
https://bugs.launchpad.net/ubuntu/+source/glibc/+bug/1485168/+subscriptions

-- 
ubuntu-bugs mailing list
ubuntu-bugs@lists.ubuntu.com
https://lists.ubuntu.com/mailman/listinfo/ubuntu-bugs

Reply via email to