0003-Fix-NULL-pointer-deref-in-XPointer-range-to.patch 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. From: Nick Wellnhofer <wellnhofer@aevum.de>
  2. Date: Sat, 25 Jun 2016 12:35:50 +0200
  3. Subject: Fix NULL pointer deref in XPointer range-to
  4. - Check for errors after evaluating first operand.
  5. - Add sanity check for empty stack.
  6. Found with afl-fuzz.
  7. ---
  8. result/XPath/xptr/viderror | 4 ++++
  9. test/XPath/xptr/viderror | 1 +
  10. xpath.c | 7 ++++++-
  11. 3 files changed, 11 insertions(+), 1 deletion(-)
  12. create mode 100644 result/XPath/xptr/viderror
  13. create mode 100644 test/XPath/xptr/viderror
  14. diff --git a/result/XPath/xptr/viderror b/result/XPath/xptr/viderror
  15. new file mode 100644
  16. index 0000000..d589882
  17. --- /dev/null
  18. +++ b/result/XPath/xptr/viderror
  19. @@ -0,0 +1,4 @@
  20. +
  21. +========================
  22. +Expression: xpointer(non-existing-fn()/range-to(id('chapter2')))
  23. +Object is empty (NULL)
  24. diff --git a/test/XPath/xptr/viderror b/test/XPath/xptr/viderror
  25. new file mode 100644
  26. index 0000000..da8c53b
  27. --- /dev/null
  28. +++ b/test/XPath/xptr/viderror
  29. @@ -0,0 +1 @@
  30. +xpointer(non-existing-fn()/range-to(id('chapter2')))
  31. diff --git a/xpath.c b/xpath.c
  32. index 113bce6..751665b 100644
  33. --- a/xpath.c
  34. +++ b/xpath.c
  35. @@ -14005,9 +14005,14 @@ xmlXPathCompOpEval(xmlXPathParserContextPtr ctxt, xmlXPathStepOpPtr op)
  36. xmlNodeSetPtr oldset;
  37. int i, j;
  38. - if (op->ch1 != -1)
  39. + if (op->ch1 != -1) {
  40. total +=
  41. xmlXPathCompOpEval(ctxt, &comp->steps[op->ch1]);
  42. + CHECK_ERROR0;
  43. + }
  44. + if (ctxt->value == NULL) {
  45. + XP_ERROR0(XPATH_INVALID_OPERAND);
  46. + }
  47. if (op->ch2 == -1)
  48. return (total);