GNOME Bugzilla – Bug 161549
Node::find crashes on invalid XPath query
Last modified: 2004-12-22 21:47:04 UTC
If the user calls Node::find with an invalid XPath query (e.g. "//"), the library will try to dereference a NULL pointer and cause a SIGSEGV. The offending code is here: NodeSet Node::find(const std::string& xpath) const { xmlXPathContext* ctxt = xmlXPathNewContext(impl_->doc); ctxt->node = impl_; xmlXPathObject* result = xmlXPathEval((const xmlChar*)xpath.c_str(), ctxt); if (result->type != XPATH_NODESET) /* BOOM! */ { xmlXPathFreeObject(result); xmlXPathFreeContext(ctxt); throw internal_error("sorry, only nodeset result types supported for now."); The result of xmlPathEval should be checked before being dereferenced. I would recommend an exception be thrown when it is 0.
Thanks. Done in cvs. Please check that it works for you. Please try to create an actual cvs patch in future.