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

silvioprog silvioprog at gmail.com
Wed Jan 18 14:49:54 PST 2017


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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.aleksey.com/pipermail/xmlsec/attachments/20170118/e5611714/attachment-0001.html>


More information about the xmlsec mailing list