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 780159 - NULL deref crash in xmlParseExternalEntityPrivate()
NULL deref crash in xmlParseExternalEntityPrivate()
Status: RESOLVED FIXED
Product: libxml2
Classification: Platform
Component: parser
git master
Other All
: Normal normal
: ---
Assigned To: David Kilzer
Depends on: 767154
Blocks:
 
 
Reported: 2017-03-16 18:01 UTC by David Kilzer
Modified: 2017-07-05 18:09 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
Patch v1 (874 bytes, patch)
2017-03-16 18:11 UTC, David Kilzer
none Details | Review

Description David Kilzer 2017-03-16 18:01:42 UTC
In xmlParseExternalEntityPrivate(), the following code tries to dereference 'oldctxt':

    /*
     * And record the last error if any
     */
    if (ctxt->lastError.code != XML_ERR_OK)
        xmlCopyError(&ctxt->lastError, &oldctxt->lastError);

However, that function parameter is NULL at some call sites, such as this one in parser.c:

int
xmlParseExternalEntity(xmlDocPtr doc, xmlSAXHandlerPtr sax, void *user_data,
	  int depth, const xmlChar *URL, const xmlChar *ID, xmlNodePtr *lst) {
    return(xmlParseExternalEntityPrivate(doc, NULL, sax, user_data, depth, URL,
		                       ID, lst));
}

I can reproduce this easily with Apple's internal libxml2 repository by compiling with ASan enabled and running testapi like this:

$ ASAN_OPTIONS=redzone=128 ./testapi

However, I'm unable to reproduce the crash the same way using the upstream libxml2 repository.  (I've tried bisecting the internal repository, but haven't been successful in finding the revision that makes this reproduce.  A few changes are too old to bisect this way, but I'm continuing to work on getting approval to upstream them.)

Note that to reproduce this crash, one must also fix the issues found in Bug 767154 first.
Comment 1 David Kilzer 2017-03-16 18:11:26 UTC
Created attachment 348111 [details] [review]
Patch v1
Comment 3 David Kilzer 2017-07-05 18:09:45 UTC
(In reply to Nick Wellnhofer from comment #2)
> Fixed here:
> 
> https://git.gnome.org/browse/libxml2/commit/
> ?id=3eef3f39a646f279e88cdb2fc45b6b17211fcd74

Thanks!