Bug 523694 - getaddrinfo causes segfault if multithreaded
Summary: getaddrinfo causes segfault if multithreaded
Keywords:
Status: CLOSED NOTABUG
Alias: None
Product: Red Hat Enterprise Linux 5
Classification: Red Hat
Component: glibc
Version: 5.4
Hardware: All
OS: Linux
low
high
Target Milestone: ---
: ---
Assignee: Andreas Schwab
QA Contact: BaseOS QE
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2009-09-16 13:16 UTC by Need Real Name
Modified: 2009-09-22 13:15 UTC (History)
0 users

Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Clone Of:
Environment:
Last Closed: 2009-09-22 13:15:10 UTC


Attachments (Terms of Use)

Description Need Real Name 2009-09-16 13:16:11 UTC
Description of problem:

The getaddrinfo() function causes a internal segmentation fault if the binary is linked static and the system has more than one core (e.g. dualcore, quadcore). This behavior is not expected the function is described to be thread safe!

How reproducible:


Steps to Reproduce:
1. Need a system with multiple cores, it does not crash on single core system
2. Compile the following code
----- dnstest.cpp ----
#include <stdio.h>
#include <netdb.h>
#include <pthread.h>
#include <unistd.h>

void *test(void *)
{
        struct addrinfo *res = NULL;
        fprintf(stderr, "x=");
        int ret = getaddrinfo("localhost", NULL, NULL, &res);
        fprintf(stderr, "%d ", ret);
        return NULL;
}

int main()
{
        for (int i = 0; i < 512; i++)
        {
                pthread_t thr;
                pthread_create(&thr, NULL, test, NULL);
        }
        sleep(5);
        return 0;
}
----- dnstest.cpp ----

g++ -o dnstest -g -static dnstest.cpp -lpthread

3. Let it run
./dnstest
x=x=x=x=x=x=x=x=x=x=x=x=x=x=x=x=x=x=Segmentation fault (core dumped)

If the "-static" is not used it works fine. But we need a static binary and this should work also if linked statically. There is nothing mentioned that static linking won't work.

Expected results:
The program should print some lines with "x=0" and then end after 5 seconds.

Comment 1 Need Real Name 2009-09-16 13:17:19 UTC
This happens on RedHat 5.3 or Fedora Core 11 or also older systems.

Comment 2 Andreas Schwab 2009-09-22 13:15:10 UTC
If you want a thread safe nss service you must link dynamically against libpthread, otherwise the dynamically loaded nss service modules cannot find the pthread functions.  Alternatively, you need to statically link against the nss modules.


Note You need to log in before you can comment on or make changes to this bug.