Skip to content

Commit

Permalink
WIP: ensure we trap XML errors while applying XSLT stylesheet
Browse files Browse the repository at this point in the history
otherwise trivial XML errors will silently result in NULL being
returned by xsltApplyStylesheet() and a subsequent segfault

WIP NOTE that we need a test here to prevent regressions. The test I have
available is too large to commit to the repo.

Fixes #1802
  • Loading branch information
flavorjones committed Jan 12, 2019
1 parent df1bfa0 commit cb01e68
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions ext/nokogiri/xslt_stylesheet.c
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ static VALUE transform(int argc, VALUE* argv, VALUE self)

errstr = rb_str_new(0, 0);
xsltSetGenericErrorFunc((void *)errstr, xslt_generic_error_handler);
xmlSetGenericErrorFunc(NULL, (xmlGenericErrorFunc)&swallow_superfluous_xml_errors);
xmlSetGenericErrorFunc((void *)errstr, xslt_generic_error_handler);

result = xsltApplyStylesheet(wrapper->ss, xml, params);
free(params);
Expand All @@ -180,7 +180,11 @@ static VALUE transform(int argc, VALUE* argv, VALUE self)
rb_exc_raise(exception);
}

return Nokogiri_wrap_xml_document((VALUE)0, result) ;
if (result) {
return Nokogiri_wrap_xml_document((VALUE)0, result) ;
}

rb_raise(rb_eRuntimeError, "unknown error transforming document, please report as a bug");
}

static void method_caller(xmlXPathParserContextPtr ctxt, int nargs)
Expand Down

0 comments on commit cb01e68

Please sign in to comment.