Segfault with detached threads and OpenSSL

Rodrigo Arias rodarima@gmail.com
Sun May 19 21:29:10 GMT 2024


Hi,

(Sent to cygwin-developers by mistake).

When debugging a segfault in the Dillo browser[1] with the DNS threaded 
resolver and OpenSSL 3.0.13 I managed to isolate a reproducer.

[1]: https://github.com/dillo-browser/dillo/issues/172

It seems to be caused when both the SSL_library_init() is present and the 
PTHREAD_CREATE_DETACHED flag is set.

Steps to reproduce:

$ cat p.c
#include <pthread.h>
#include <unistd.h>
#include <stdio.h>

#include <openssl/ssl.h>

#define N 4

static void *foo(void *data)
{
         printf("hello th %d\n", (int) data);
         return NULL;
}

int main()
{
         SSL_library_init();
         pthread_t th[N];
         pthread_attr_t attr;
         pthread_attr_init(&attr);
         pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);

         for (int i = 0; i < N; i++)
                 pthread_create(&th[i], &attr, foo, (void *) i);

         sleep(5);
}

$ gcc p.c -lssl -pthread -o p

$ gdb ./p
GNU gdb (GDB) (Cygwin 13.2-1) 13.2
Copyright (C) 2023 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Type "show copying" and "show warranty" for details.
This GDB was configured as "x86_64-pc-cygwin".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<https://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
     <http://www.gnu.org/software/gdb/documentation/>.

For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from ./p...
(gdb) r
Starting program: /home/PC/dillo/build-openssl/p
[New Thread 7332.0x1f2c]
[New Thread 7332.0x99c]
[New Thread 7332.0x27d4]
[New Thread 7332.0x35e0]
[New Thread 7332.0x21dc]
[New Thread 7332.0x3170]
[New Thread 7332.0x1ea4]
[New Thread 7332.0x3180]
hello th 0
hello th 1
hello th 2
[Thread 7332.0x3170 exited with code 0]
hello th 3

Thread 6 "p" received signal SIGSEGV, Segmentation fault.
[Switching to Thread 7332.0x21dc]
0x0000000000000000 in ?? ()

Thanks,
Rodrigo.


More information about the Cygwin mailing list