[stunnel-users] Fix unexpected stunnel-4.10 exits on FreeBSD

Vasil Dimov vd at datamax.bg
Tue Jun 14 14:08:27 CEST 2005


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On Mon, Jun 13, 2005 at 10:53:00PM +0200, Michal Trojnara wrote:
> 
> *** sthreads.c.old      Mon Jun 13 21:34:53 2005
> --- sthreads.c  Mon Jun 13 22:15:01 2005
> ***************
> *** 63,68 ****
> --- 63,69 ----
> 
>   static void ctx_cleanup_func(void) { /* cleanup the active thread */
>       s_log(LOG_DEBUG, "Context %ld closed", ready_head->id);
> +     makecontext(&ctx_cleanup, ctx_cleanup_func, 0);
>       s_poll_wait(NULL, 0); /* wait on poll() */
>   }
> 
> It's quite simple and it works.  8-)  It's on my FTP site, now.
> 

Changing the currently executing context (with makecontext) does not
seem very robust to me, but, however, I am not an ucontext expert
(in fact I have not heard about it before beginning to experience
problems with stunnel-4.10).

> 
> BTW: It still doesn't work on my UML (User-Mode Linux) host:
> 2005.06.13 22:43:23 LOG7[30415:0]: CONTEXT 1, FD=3, (IN)->()
> 2005.06.13 22:43:23 LOG7[30415:0]: CONTEXT 1, FD=5, (IN)->(IN)
> 2005.06.13 22:43:23 LOG7[30415:1]: Switching from context 1 to context 1
> 2005.06.13 22:43:23 LOG7[30415:1]: Context switched
> 2005.06.13 22:43:23 LOG7[30415:1]: TST_SVC accepted FD=6 from 
> 127.0.0.1:3411
> 2005.06.13 22:43:23 LOG7[30415:1]: Creating a new context
> 2005.06.13 22:43:23 LOG7[30415:1]: Context 2 created
> 2005.06.13 22:43:23 LOG7[30415:2]: Switching from context 1 to context 2
> Segmentation fault      ./stunnel stunnel.conf
> 
> It fails on a first non-trivial context switch.  Any idea?

Hmm, what is this version of stunnel?
4.10 does not print "Switching from context M to context N",
"Context switched", etc.

Is the number after the pid showing the thread id? How is it possible
that context2 prints "Switching from context 1 to context 2", shouldnt
this be printed by context 1?

I have tested 4.10 with yours bsd.patch and it works on Linux 2.4.18-14,
Red Hat Linux release 8.0 (Psyche).

Do you confirm that stunnel begins to crash after applying bsd.patch on
your User-Mode Linux?

Does the Context 2 function start execution at all, or the program
crashes before that?

Some of the obvious reasons for the above crash can be:

1. invalid pointer given as a first argument to swapcontext(), e.g.
  nowhere to save the old context.
2. the new context (second argument) is somehow inconsistent. This
  includes the whole pointer, inaccessible function given to
  makecontext in initializaion, the argument not initialized with
  getcontext, uc_link is bogus, or something else.

I noticed that backtraces of ucontexting programs are not very useful,
but can you retrieve a backtrace from the core file? What does it show?
Running the program via gdb and stepping while the crash occurs may also
be helpful.

Regards,
Vasil
-----BEGIN PGP SIGNATURE-----

iD8DBQFCrsi7Fw6SP/bBpCARAjIuAKDaKnbuWmFbxlz/WwRXni/en9bRDACg05i8
ZCDZt6DPmDIY2iSbm47Y3ug=
=gRbm
-----END PGP SIGNATURE-----



More information about the stunnel-users mailing list