0007-Fix-more-NULL-pointer-derefs-in-xpointer.c.patch 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. From e905f08123e4a6e7731549e6f09dadff4cab65bd Mon Sep 17 00:00:00 2001
  2. From: Nick Wellnhofer <wellnhofer@aevum.de>
  3. Date: Sun, 26 Jun 2016 12:38:28 +0200
  4. Subject: [PATCH] Fix more NULL pointer derefs in xpointer.c
  5. Found with afl-fuzz.
  6. ---
  7. xpointer.c | 12 +++++++-----
  8. 1 file changed, 7 insertions(+), 5 deletions(-)
  9. diff --git a/xpointer.c b/xpointer.c
  10. index 694d120..e643ee9 100644
  11. --- a/xpointer.c
  12. +++ b/xpointer.c
  13. @@ -542,7 +542,7 @@ xmlXPtrNewRangeNodeObject(xmlNodePtr start, xmlXPathObjectPtr end) {
  14. /*
  15. * Empty set ...
  16. */
  17. - if (end->nodesetval->nodeNr <= 0)
  18. + if ((end->nodesetval == NULL) || (end->nodesetval->nodeNr <= 0))
  19. return(NULL);
  20. endNode = end->nodesetval->nodeTab[end->nodesetval->nodeNr - 1];
  21. endIndex = -1;
  22. @@ -1361,7 +1361,7 @@ xmlXPtrEval(const xmlChar *str, xmlXPathContextPtr ctx) {
  23. */
  24. xmlNodeSetPtr set;
  25. set = tmp->nodesetval;
  26. - if ((set->nodeNr != 1) ||
  27. + if ((set == NULL) || (set->nodeNr != 1) ||
  28. (set->nodeTab[0] != (xmlNodePtr) ctx->doc))
  29. stack++;
  30. } else
  31. @@ -2034,9 +2034,11 @@ xmlXPtrRangeFunction(xmlXPathParserContextPtr ctxt, int nargs) {
  32. xmlXPathFreeObject(set);
  33. XP_ERROR(XPATH_MEMORY_ERROR);
  34. }
  35. - for (i = 0;i < oldset->locNr;i++) {
  36. - xmlXPtrLocationSetAdd(newset,
  37. - xmlXPtrCoveringRange(ctxt, oldset->locTab[i]));
  38. + if (oldset != NULL) {
  39. + for (i = 0;i < oldset->locNr;i++) {
  40. + xmlXPtrLocationSetAdd(newset,
  41. + xmlXPtrCoveringRange(ctxt, oldset->locTab[i]));
  42. + }
  43. }
  44. /*
  45. --
  46. 2.1.4