CVE-2021-3518 libxml2 use-after-free in xmlXIncludeCopyNode during recursive XInclude
a73e31bf-95a7-450b-923f-e07be1cfe74f
libxml2 v2.9.11 has a use-after-free vulnerability (CVE-2021-3518) in XInclude processing when handling recursive/nested includes. The XInclude context (xmlXIncludeCtxt) keeps a side-table of include references (incTab) where each entry stores a raw xmlNodePtr (->ref) into the source tree. During recursive XInclude expansion, xmlXIncludeIncludeNode in xinclude.c frees fallback children of an XInclude element via xmlUnlinkNode/xmlFreeNode at lines 2253-2259, but it does NOT invalidate incTab entries whose ->ref pointers live inside that freed subtree. Subsequent passes — xmlXIncludeIncludeNode line 2201 ('cur = ctxt->incTab[nr]->ref'), xmlXIncludeCopyNode line 844 ('xmlDocCopyNode(elem, target, 1)'), and xmlXIncludeCopyNodeList line 868 walking 'cur->next' — dereference these dangling pointers. The 'count' refcount used in xmlXIncludeRecurseDoc only protects the xmlXIncludeRefPtr wrapper struct, not the xmlNodePtr it wraps.