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

silvioprog silvioprog at gmail.com
Sat Jan 21 06:15:42 PST 2017


Oh, please sorry. ^^' I don't know why my e-mail client sometimes send the
message to a particular e-mail instead of the mail-list. o.O

On Fri, Jan 20, 2017 at 12:10 AM, Aleksey Sanin <aleksey at aleksey.com> wrote:

> Great, you might want to re-post it to the xmlsec at aleksey.com mailing
> list so people can find this post in the future.
>
> Aleksey
>
> On 1/19/17 8:14 AM, silvioprog wrote:
> > Finally fixed this problem using an object as error handler! If someone
> > want to take a look at the final code, it was sent to:
> https://git.io/vMDNR.
> >
> > Thanks! :-)
> >
> > On Thu, Jan 19, 2017 at 11:12 AM, silvioprog <silvioprog at gmail.com
> > <mailto:silvioprog at gmail.com>> wrote:
> >
> >     Attached example that reproduces the problem. Notice commenting the
> >     line "#define DAMN_SIGILL 1".
> >
> >     To compile and run:
> >
> >     $ cmake . && make && ./sigsegv
> >
> >     On Thu, Jan 19, 2017 at 1:10 AM, silvioprog <silvioprog at gmail.com
> >     <mailto:silvioprog at gmail.com>> wrote:
> >
> >         It seems the problem is related to nested function's life cycle:
> >
> >         1. my `extern mxml_xml_init()` set the `_error_callback()`
> >         nested reference function to `xmlSetGenericErrorFunc()`;
> >         2. my `mxml_xml_validate_file()` calls the
> >         `xmlSchemaValidateFile()`, but the `_error_callback()` was freed
> >         by the `mxml_xml_init()` scope, raising the SIGSEGV.
> >
> >         But I'm not absolutely sure about it anyway.
> >
> >         Is there functions like `xmlSetGenericErrorFunc()`, however,
> >         using a `va_list` parameter instead off "..." `varargs`?
> >
> >         On Wed, Jan 18, 2017 at 9:19 PM, silvioprog
> >         <silvioprog at gmail.com <mailto:silvioprog at gmail.com>> wrote:
> >
> >             Indeed. I forgot to show my environment too:
> >
> >             Xubuntu 16.04 64 bits
> >             gcc (Ubuntu 5.4.0-6ubuntu1~16.04.4) 5.4.0 20160609
> >             libxml-2.0 - 2.9.3 (installed via apt-get)
> >             xmlsec1 - 1.2.20 (installed via apt-get)
> >
> >             Unfortunately the GBD log[1] doesn't show any precise info
> >             about the error. I notice that commenting the line
> >             "xmlSetGenericErrorFunc(error_cls, &_error_callback);" the
> >             sigsegv stops, however I need to call my own callback. I
> >             tested declaring the "_error_callback" outside function too,
> >             like:
> >
> >             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);
> >             //    }
> >             }
> >
> >             void mxml_xml_init(mxml_error_callback error_cb, void
> >             *error_cls) {
> >                 xmlInitParser();
> >                 xmlSetGenericErrorFunc(error_cls, &_error_callback);
> >             }
> >
> >             and the problem was solved, but notice commented lines, in
> >             that way I can't use my "error_cb" anymore. :-(
> >
> >             And the sigsegv happen when my library call the function
> >             "xmlSchemaSetValidErrors(cfg->ctxt, &_error_callback,
> >             &_warn_callback, error_warn_cls);".
> >
> >             [1]
> >             GNU gdb (GDB) 7.11.1
> >             Copyright (C) 2016 Free Software Foundation, Inc.
> >             License GPLv3+: GNU GPL version 3 or later
> >             <http://gnu.org/licenses/gpl.html
> >             <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-linux-gnu".
> >             Type "show configuration" for configuration details.
> >             For bug reporting instructions, please see:
> >             <http://www.gnu.org/software/gdb/bugs/
> >             <http://www.gnu.org/software/gdb/bugs/>>.
> >             Find the GDB manual and other documentation resources online
> at:
> >             <http://www.gnu.org/software/gdb/documentation/
> >             <http://www.gnu.org/software/gdb/documentation/>>.
> >             For help, type "help".
> >             Type "apropos word" to search for commands related to "word".
> >             No source file named
> >             /home/silvioprog/dev/git/ws/libmicroxml/src/microxml.c.
> >             [Thread debugging using libthread_db enabled]
> >             Using host libthread_db library
> >             "/lib/x86_64-linux-gnu/libthread_db.so.1".
> >
> >             Breakpoint 1, main (argc=3, argv=0x7fffffffe158) at
> >             /home/silvioprog/dev/git/ws/libmicroxml/examples/c/
> validate.c:19
> >             19   if (3 != argc) {
> >
> >             Breakpoint 2, mxml_xml_init (error_cb=0x400a06
> >             <error_callback>) at
> >             /home/silvioprog/dev/git/ws/libmicroxml/src/microxml.c:85
> >             85   xmlSetGenericErrorFunc(error_cls, &_error_callback);
> >
> >             Program received signal SIGSEGV, Segmentation fault.
> >             0x00007fffffffdf10 in ?? ()
> >
> >             On Wed, Jan 18, 2017 at 8:20 PM, Aleksey Sanin
> >             <aleksey at aleksey.com <mailto:aleksey at aleksey.com>> wrote:
> >
> >                 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
> >
> >
> >             --
> >             Silvio Clécio
> >
> >
> >         --
> >         Silvio Clécio
> >
> >
> >     --
> >     Silvio Clécio
> >
> >
> > --
> > Silvio Clécio
>



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


More information about the xmlsec mailing list