[xmlsec] Interrupted by signal 11 SIGSEGV using a nested function to handle errors

silvioprog silvioprog at gmail.com
Sat Jan 21 06:40:52 PST 2017


Hello Michel, thanks for replying.

I'm using `cdecl`. :-)

The problem was related to C nested function: its life-cycle is strictly
limited to the scope caller. Something like this:

some_global_function_using_a_nested_callback_function() {
    some_nested_callback_function() { // << its life-cycle dies ...
    }
    some_callback_register(&some_nested_callback_function);
} // ... here! x-(

After declaring this code above, if you call
`some_global_function_using_a_nested_callback_function()` in any place, you
may get a terrible SIGSEGV. :-)

I declared it as nested function because I need to access the
`some_global_function_using_a_nested_callback_function()`'s parameters, so
finally I solved the problem just declaring an extra struct::

struct some_callback_handler {
  my_particular_callback;
  my_particular_callback_cls;
}

static some_global_callback_function(some_callback_handler) { // << at
last, its life-cycle is global! ^.^

some_callback_handler.my_particular_callback(some_callback_handler.my_particular_callback_cls);
}

some_global_function_using_a_global_callback_function(the_xmlsec_callback) {

some_xmlsec_callback_register(global_handler, &some_global_callback_function);
}

https://www.aleksey.com/pipermail/xmlsec/2017/010098.html

Final implementation (without nested funcs):
https://github.com/silvioprog/ws/blob/master/libmicroxml/src/microxml.c#L126
.

I need to take care with nested functions in C, I think I'll never use it
anymore. -.-

Thanks!

(I sent the last message to the Aleksey's e-mail by mistake hehe ^^' )

On Fri, Jan 20, 2017 at 5:25 PM, iso8583 <iso8583 at free.fr> wrote:

> HI,
>
>
>
> > I can't understand why it doesn't work. It seems my local function has
> the same signature of `xmlGenericErrorFunc` function, but... :-(
>
>
>
> As you mentioned you are working in Pascal, it may not be just because of
> the signature of the function.
>
> Is it not actually a ‘calling convention’ problem ?
>
> https://en.wikipedia.org/wiki/X86_calling_conventions
>
>
>
> Hope it helps,
>
>
>
> Regards,
>
>
>
> Michel.
>

-- 
Silvio Clécio
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.aleksey.com/pipermail/xmlsec/attachments/20170121/e5836da9/attachment.html>


More information about the xmlsec mailing list