public inbox for cygwin-developers@cygwin.com
 help / color / mirror / Atom feed
* Segfault with detached threads and OpenSSL
@ 2024-05-19 21:26 Rodrigo Arias
  0 siblings, 0 replies; only message in thread
From: Rodrigo Arias @ 2024-05-19 21:26 UTC (permalink / raw)
  To: cygwin-developers

Hi,

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.

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2024-05-19 21:26 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-05-19 21:26 Segfault with detached threads and OpenSSL Rodrigo Arias

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).