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

Aleksey Sanin aleksey at aleksey.com
Wed Jan 18 15:20:04 PST 2017


You probably want to get a precise location of sigsegv with gdb.

Aleksey

On 1/18/17 2:49 PM, silvioprog wrote:
> Hello masters,
> 
> I'm trying to use the following code in a library that extends
> libxml2/xmlsec1:
> 
> ...
> 
> typedef void (*mxml_error_callback)(void *cls, const char *msg);
> 
> ...
> 
> void mxml_xml_init(mxml_error_callback error_cb, void *error_cls) {
> 
>     void _error_callback(void *cls, const char *fmt, ...) {
>         char *error;
>         char msg[MXML_ERROR_MAX_SIZE];
>         if (NULL != error_cb) {
>             va_list va;
>             va_start(va, fmt);
>             vasprintf(&error, fmt, va);
>             strcpy(msg, error);
>             free(error);
>             va_end(va);
>             error_cb(error_cls, msg);
>         }
>     }
> 
>     xmlInitParser();
>     xmlSetGenericErrorFunc(error_cls, &_error_callback);
> }
> 
> ...
> 
> However, when I run my project, I got a "interrupted by signal 11:
> SIGSEGV", even commenting the entire local code, eg:
> 
> ...
> 
> void mxml_xml_init(mxml_error_callback error_cb, void *error_cls) {
>     void _error_callback(void *cls, const char *fmt, ...) {
>     }
>     xmlInitParser();
>     xmlSetGenericErrorFunc(error_cls, &_error_callback);
> }
> 
> ...
> 
> Unfortunately, I need to publish something like `mxml_error_callback`
> instead of default `xmlGenericErrorFunc` because some languages (eg:
> Pascal) doesn't offer any feature to get the parameters of a `varargs`
> function, so I want pass only a "const char *msg" to them.
> 
> I have other declarations like this that causes SIGSEGV too:
> 
> ...
> 
> struct mxml_xml_cfg *mxml_xml_cfg_new(const char *xsd_uri,
>                                       mxml_error_callback error_cb,
>                                       mxml_error_callback warn_cb, void
> *error_warn_cls) {
> 
>     void _error_callback(void *cls, const char *fmt, ...) {
> ... code ...
>     }
> 
>     void _warn_callback(void *cls, const char *fmt, ...) {
> ... code ...
>     }
> 
> ... code ...
> ... code ...
> ... code ...
>     xmlSchemaSetParserErrors(cfg->parser, &_error_callback,
> &_warn_callback, error_warn_cls);
> 
> ...
> 
> I can't understand why it doesn't work. It seems my local function has
> the same signature of `xmlGenericErrorFunc` function, but... :-(
> 
> A snip of the main test:
> 
> ...
> 
> static void error_callback(void *cls, const char *msg) {
>     fprintf(stderr, "%s", msg);
> }
> 
> int main() {
> ...
>     mxml_xml_init(&error_callback, NULL);
> 
> ...
> 
> Thank you!
> 
> --
> Silvio Clécio
> 
> 
> _______________________________________________
> xmlsec mailing list
> xmlsec at aleksey.com
> http://www.aleksey.com/mailman/listinfo/xmlsec
> 


More information about the xmlsec mailing list