After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 645269 - Default error func called in multi-thread apps instead of error func specified
Default error func called in multi-thread apps instead of error func specified
Status: RESOLVED OBSOLETE
Product: libxml2
Classification: Platform
Component: general
2.7.7
Other Linux
: Normal normal
: ---
Assigned To: Daniel Veillard
libxml QA maintainers
Depends on:
Blocks:
 
 
Reported: 2011-03-19 22:41 UTC by Xavier Conde
Modified: 2021-07-05 13:22 UTC
See Also:
GNOME target: ---
GNOME version: ---



Description Xavier Conde 2011-03-19 22:41:30 UTC
Hi,

In my app I use threads when parsing XML files. It seems that in this case when I specify a generic error function with xmlSetGenericErrorFunc () my function is not called and instead the default function is called, leading to a crash. If I don't use threads in my app, the fuction I've specified is called succesfully and the app doesn't crash.

This is the backtrace of the crash:

  • #0 __vfprintf_chk
    from /lib/libc.so.6
  • #1 xmlGenericErrorDefaultFunc
    from /usr/lib/libxml2.so.2
  • #2 ??
    from /usr/lib/libxml2.so.2
  • #3 __xmlRaiseError
    from /usr/lib/libxml2.so.2
  • #4 __xmlSimpleError
    from /usr/lib/libxml2.so.2
  • #5 ??
    from /usr/lib/libxml2.so.2
  • #6 xmlStringGetNodeList
    from /usr/lib/libxml2.so.2
  • #7 xmlNewDocNode
    from /usr/lib/libxml2.so.2
  • #8 xmlNewChild
    from /usr/lib/libxml2.so.2
  • #9 saleena_html_content_channel_create_channel_item
    at SaleenaHTMLContentChannel.c line 109
  • #10 saleena_html_content_channel_create_content
    at SaleenaHTMLContentChannel.c line 209
  • #11 saleena_channel_html_content_create
    at SaleenaChannelHTMLContent.c line 82
  • #12 saleena_html_content_create_content
    at SaleenaHTMLContent.c line 334
  • #13 saleena_html_content_do
    at SaleenaHTMLContent.c line 411
  • #14 ??
    from /lib/libglib-2.0.so.0
  • #15 start_thread
    from /lib/libpthread.so.0
  • #16 clone
    from /lib/libc.so.6

Thanks in advance!
Comment 1 Paavo Helde 2011-11-23 23:48:47 UTC
I have seen the same or similar bug in a fresh compilation of libxml2 2.7.8. It seems however the crash is not related to generic error function setting, I get it also when I do not call xmlSetGenericErrorFunc() at all.

It seems the segfault appears when some error is reported in a background thread, in my case it was "Namespace prefix %s for %s on %s is not defined\n" reported from xmlParseStartTag2 at parser.c:9191

I was able to avoid the crash by changing the code in function xmlGenericErrorDefaultFunc() to avoid assigning to xmlGenericErrorContext, but using a local variable instead. It seems that xmlGenericErrorContext is a kind of thread-specific pseudovariable, and assigning to it does not really work:

xmlGenericErrorDefaultFunc (ctx=0x0, msg=0x7f9bca75cf43 "namespace ") at error.c:75
75              xmlGenericErrorContext = (void *) stderr;
(gdb) n
77          va_start(args, msg);
(gdb) p stderr
$14 = (struct _IO_FILE *) 0x7f9bdd0d2860
(gdb) p xmlGenericErrorContext
$15 = (void *) 0x7f9bb035fce0

It appears that the just saved value has changed to some garbage, and this is confirmed by vfprintf() a couple of lines later which is attempting to use xmlGenericErrorContext as a FILE* pointer and failing with a segfault.

The original bug about not calling the custom error handler is still present. The error handler has been set in the same background thread.
Comment 2 GNOME Infrastructure Team 2021-07-05 13:22:40 UTC
GNOME is going to shut down bugzilla.gnome.org in favor of gitlab.gnome.org.
As part of that, we are mass-closing older open tickets in bugzilla.gnome.org
which have not seen updates for a longer time (resources are unfortunately
quite limited so not every ticket can get handled).

If you can still reproduce the situation described in this ticket in a recent
and supported software version, then please follow
  https://wiki.gnome.org/GettingInTouch/BugReportingGuidelines
and create a new ticket at
  https://gitlab.gnome.org/GNOME/libxml2/-/issues/

Thank you for your understanding and your help.