Adding various checks on node type though the API

Specifially checking against namespace nodes before accessing node
pointers
This commit is contained in:
Daniel Veillard 2012-08-09 14:24:02 +08:00
parent 6ca24a39d0
commit 3e62adbe39
7 changed files with 110 additions and 54 deletions

80
tree.c
View File

@ -2779,7 +2779,7 @@ void
xmlSetTreeDoc(xmlNodePtr tree, xmlDocPtr doc) {
xmlAttrPtr prop;
if (tree == NULL)
if ((tree == NULL) || (tree->type == XML_NAMESPACE_DECL))
return;
if (tree->doc != doc) {
if(tree->type == XML_ELEMENT_NODE) {
@ -2807,7 +2807,7 @@ void
xmlSetListDoc(xmlNodePtr list, xmlDocPtr doc) {
xmlNodePtr cur;
if (list == NULL)
if ((list == NULL) || (list->type == XML_NAMESPACE_DECL))
return;
cur = list;
while (cur != NULL) {
@ -2914,7 +2914,9 @@ static xmlNodePtr
xmlAddPropSibling(xmlNodePtr prev, xmlNodePtr cur, xmlNodePtr prop) {
xmlAttrPtr attr;
if (cur->type != XML_ATTRIBUTE_NODE)
if ((cur == NULL) || (cur->type != XML_ATTRIBUTE_NODE) ||
(prop == NULL) || (prop->type != XML_ATTRIBUTE_NODE) ||
((prev != NULL) && (prev->type != XML_ATTRIBUTE_NODE)))
return(NULL);
/* check if an attribute with the same name exists */
@ -2962,14 +2964,14 @@ xmlAddPropSibling(xmlNodePtr prev, xmlNodePtr cur, xmlNodePtr prop) {
*/
xmlNodePtr
xmlAddNextSibling(xmlNodePtr cur, xmlNodePtr elem) {
if (cur == NULL) {
if ((cur == NULL) || (cur->type == XML_NAMESPACE_DECL)) {
#ifdef DEBUG_TREE
xmlGenericError(xmlGenericErrorContext,
"xmlAddNextSibling : cur == NULL\n");
#endif
return(NULL);
}
if (elem == NULL) {
if ((elem == NULL) || (elem->type == XML_NAMESPACE_DECL)) {
#ifdef DEBUG_TREE
xmlGenericError(xmlGenericErrorContext,
"xmlAddNextSibling : elem == NULL\n");
@ -3040,14 +3042,14 @@ xmlAddNextSibling(xmlNodePtr cur, xmlNodePtr elem) {
*/
xmlNodePtr
xmlAddPrevSibling(xmlNodePtr cur, xmlNodePtr elem) {
if (cur == NULL) {
if ((cur == NULL) || (cur->type == XML_NAMESPACE_DECL)) {
#ifdef DEBUG_TREE
xmlGenericError(xmlGenericErrorContext,
"xmlAddPrevSibling : cur == NULL\n");
#endif
return(NULL);
}
if (elem == NULL) {
if ((elem == NULL) || (elem->type == XML_NAMESPACE_DECL)) {
#ifdef DEBUG_TREE
xmlGenericError(xmlGenericErrorContext,
"xmlAddPrevSibling : elem == NULL\n");
@ -3118,7 +3120,7 @@ xmlNodePtr
xmlAddSibling(xmlNodePtr cur, xmlNodePtr elem) {
xmlNodePtr parent;
if (cur == NULL) {
if ((cur == NULL) || (cur->type == XML_NAMESPACE_DECL)) {
#ifdef DEBUG_TREE
xmlGenericError(xmlGenericErrorContext,
"xmlAddSibling : cur == NULL\n");
@ -3126,7 +3128,7 @@ xmlAddSibling(xmlNodePtr cur, xmlNodePtr elem) {
return(NULL);
}
if (elem == NULL) {
if ((elem == NULL) || (elem->type == XML_NAMESPACE_DECL)) {
#ifdef DEBUG_TREE
xmlGenericError(xmlGenericErrorContext,
"xmlAddSibling : elem == NULL\n");
@ -3194,7 +3196,7 @@ xmlNodePtr
xmlAddChildList(xmlNodePtr parent, xmlNodePtr cur) {
xmlNodePtr prev;
if (parent == NULL) {
if ((parent == NULL) || (parent->type == XML_NAMESPACE_DECL)) {
#ifdef DEBUG_TREE
xmlGenericError(xmlGenericErrorContext,
"xmlAddChildList : parent == NULL\n");
@ -3202,7 +3204,7 @@ xmlAddChildList(xmlNodePtr parent, xmlNodePtr cur) {
return(NULL);
}
if (cur == NULL) {
if ((cur == NULL) || (cur->type == XML_NAMESPACE_DECL)) {
#ifdef DEBUG_TREE
xmlGenericError(xmlGenericErrorContext,
"xmlAddChildList : child == NULL\n");
@ -3280,7 +3282,7 @@ xmlNodePtr
xmlAddChild(xmlNodePtr parent, xmlNodePtr cur) {
xmlNodePtr prev;
if (parent == NULL) {
if ((parent == NULL) || (parent->type == XML_NAMESPACE_DECL)) {
#ifdef DEBUG_TREE
xmlGenericError(xmlGenericErrorContext,
"xmlAddChild : parent == NULL\n");
@ -3288,7 +3290,7 @@ xmlAddChild(xmlNodePtr parent, xmlNodePtr cur) {
return(NULL);
}
if (cur == NULL) {
if ((cur == NULL) || (cur->type == XML_NAMESPACE_DECL)) {
#ifdef DEBUG_TREE
xmlGenericError(xmlGenericErrorContext,
"xmlAddChild : child == NULL\n");
@ -3402,7 +3404,7 @@ xmlAddChild(xmlNodePtr parent, xmlNodePtr cur) {
*/
xmlNodePtr
xmlGetLastChild(xmlNodePtr parent) {
if (parent == NULL) {
if ((parent == NULL) || (parent->type == XML_NAMESPACE_DECL)) {
#ifdef DEBUG_TREE
xmlGenericError(xmlGenericErrorContext,
"xmlGetLastChild : parent == NULL\n");
@ -3836,14 +3838,15 @@ xmlUnlinkNode(xmlNodePtr cur) {
xmlNodePtr
xmlReplaceNode(xmlNodePtr old, xmlNodePtr cur) {
if (old == cur) return(NULL);
if ((old == NULL) || (old->parent == NULL)) {
if ((old == NULL) || (old->type == XML_NAMESPACE_DECL) ||
(old->parent == NULL)) {
#ifdef DEBUG_TREE
xmlGenericError(xmlGenericErrorContext,
"xmlReplaceNode : old == NULL or without parent\n");
#endif
return(NULL);
}
if (cur == NULL) {
if ((cur == NULL) || (cur->type == XML_NAMESPACE_DECL)) {
xmlUnlinkNode(old);
return(old);
}
@ -3957,6 +3960,8 @@ xmlCopyPropInternal(xmlDocPtr doc, xmlNodePtr target, xmlAttrPtr cur) {
xmlAttrPtr ret;
if (cur == NULL) return(NULL);
if ((target != NULL) && (target->type != XML_ELEMENT_NODE))
return(NULL);
if (target != NULL)
ret = xmlNewDocProp(target->doc, cur->name, NULL);
else if (doc != NULL)
@ -4076,6 +4081,8 @@ xmlCopyPropList(xmlNodePtr target, xmlAttrPtr cur) {
xmlAttrPtr ret = NULL;
xmlAttrPtr p = NULL,q;
if ((target != NULL) && (target->type != XML_ELEMENT_NODE))
return(NULL);
while (cur != NULL) {
q = xmlCopyProp(target, cur);
if (q == NULL)
@ -4576,7 +4583,7 @@ xmlGetNodePath(xmlNodePtr node)
char nametemp[100];
int occur = 0, generic;
if (node == NULL)
if ((node == NULL) || (node->type == XML_NAMESPACE_DECL))
return (NULL);
buf_len = 500;
@ -4841,7 +4848,7 @@ xmlDocSetRootElement(xmlDocPtr doc, xmlNodePtr root) {
xmlNodePtr old = NULL;
if (doc == NULL) return(NULL);
if (root == NULL)
if ((root == NULL) || (root->type == XML_NAMESPACE_DECL))
return(NULL);
xmlUnlinkNode(root);
xmlSetTreeDoc(root, doc);
@ -4928,6 +4935,8 @@ xmlChar *
xmlNodeGetLang(xmlNodePtr cur) {
xmlChar *lang;
if ((cur == NULL) || (cur->type == XML_NAMESPACE_DECL))
return(NULL);
while (cur != NULL) {
lang = xmlGetNsProp(cur, BAD_CAST "lang", XML_XML_NAMESPACE);
if (lang != NULL)
@ -5007,6 +5016,8 @@ int
xmlNodeGetSpacePreserve(xmlNodePtr cur) {
xmlChar *space;
if ((cur == NULL) || (cur->type != XML_ELEMENT_NODE))
return(-1);
while (cur != NULL) {
space = xmlGetNsProp(cur, BAD_CAST "space", XML_XML_NAMESPACE);
if (space != NULL) {
@ -5173,6 +5184,8 @@ xmlNodeGetBase(xmlDocPtr doc, xmlNodePtr cur) {
if ((cur == NULL) && (doc == NULL))
return(NULL);
if ((cur != NULL) && (cur->type == XML_NAMESPACE_DECL))
return(NULL);
if (doc == NULL) doc = cur->doc;
if ((doc != NULL) && (doc->type == XML_HTML_DOCUMENT_NODE)) {
cur = doc->children;
@ -5807,6 +5820,9 @@ xmlGetNsList(xmlDocPtr doc ATTRIBUTE_UNUSED, xmlNodePtr node)
int maxns = 10;
int i;
if ((node == NULL) || (node->type == XML_NAMESPACE_DECL))
return(NULL);
while (node != NULL) {
if (node->type == XML_ELEMENT_NODE) {
cur = node->nsDef;
@ -5905,7 +5921,7 @@ xmlSearchNs(xmlDocPtr doc, xmlNodePtr node, const xmlChar *nameSpace) {
xmlNsPtr cur;
xmlNodePtr orig = node;
if (node == NULL) return(NULL);
if ((node == NULL) || (node->type == XML_NAMESPACE_DECL)) return(NULL);
if ((nameSpace != NULL) &&
(xmlStrEqual(nameSpace, (const xmlChar *)"xml"))) {
if ((doc == NULL) && (node->type == XML_ELEMENT_NODE)) {
@ -6035,7 +6051,7 @@ xmlSearchNsByHref(xmlDocPtr doc, xmlNodePtr node, const xmlChar * href)
xmlNodePtr orig = node;
int is_attr;
if ((node == NULL) || (href == NULL))
if ((node == NULL) || (node->type == XML_NAMESPACE_DECL) || (href == NULL))
return (NULL);
if (xmlStrEqual(href, XML_XML_NAMESPACE)) {
/*
@ -6126,7 +6142,7 @@ xmlNewReconciliedNs(xmlDocPtr doc, xmlNodePtr tree, xmlNsPtr ns) {
xmlChar prefix[50];
int counter = 1;
if (tree == NULL) {
if ((tree == NULL) || (tree->type != XML_ELEMENT_NODE)) {
#ifdef DEBUG_TREE
xmlGenericError(xmlGenericErrorContext,
"xmlNewReconciliedNs : tree == NULL\n");
@ -7983,6 +7999,8 @@ xmlDOMWrapNSNormGatherInScopeNs(xmlNsMapPtr *map,
if ((map == NULL) || (*map != NULL))
return (-1);
if ((node == NULL) || (node->type == XML_NAMESPACE_DECL))
return (-1);
/*
* Get in-scope ns-decls of @parent.
*/
@ -8250,6 +8268,8 @@ xmlSearchNsByNamespaceStrict(xmlDocPtr doc, xmlNodePtr node,
if ((doc == NULL) || (nsName == NULL) || (retNs == NULL))
return (-1);
if ((node == NULL) || (node->type == XML_NAMESPACE_DECL))
return(-1);
*retNs = NULL;
if (xmlStrEqual(nsName, XML_XML_NAMESPACE)) {
@ -8348,8 +8368,8 @@ xmlSearchNsByPrefixStrict(xmlDocPtr doc, xmlNodePtr node,
xmlNodePtr cur;
xmlNsPtr ns;
if ((doc == NULL) || (node == NULL))
return (-1);
if ((doc == NULL) || (node == NULL) || (node->type == XML_NAMESPACE_DECL))
return(-1);
if (retNs)
*retNs = NULL;
@ -8417,6 +8437,9 @@ xmlDOMWrapNSNormDeclareNsForced(xmlDocPtr doc,
char buf[50];
const xmlChar *pref;
int counter = 0;
if ((doc == NULL) || (elem == NULL) || (elem->type != XML_ELEMENT_NODE))
return(NULL);
/*
* Create a ns-decl on @anchor.
*/
@ -8933,6 +8956,9 @@ xmlDOMWrapAdoptBranch(xmlDOMWrapCtxtPtr ctxt,
parnsdone = 0;
cur = node;
if ((cur != NULL) && (cur->type == XML_NAMESPACE_DECL))
goto internal_error;
while (cur != NULL) {
/*
* Paranoid source-doc sanity check.
@ -9312,6 +9338,9 @@ xmlDOMWrapCloneNode(xmlDOMWrapCtxtPtr ctxt,
*resNode = NULL;
cur = node;
if ((cur != NULL) && (cur->type == XML_NAMESPACE_DECL))
return(-1);
while (cur != NULL) {
if (cur->doc != sourceDoc) {
/*
@ -9829,6 +9858,8 @@ xmlDOMWrapAdoptAttr(xmlDOMWrapCtxtPtr ctxt,
if (attr->children == NULL)
return (0);
cur = attr->children;
if ((cur != NULL) && (cur->type == XML_NAMESPACE_DECL))
goto internal_error;
while (cur != NULL) {
cur->doc = destDoc;
switch (cur->type) {
@ -9913,7 +9944,8 @@ xmlDOMWrapAdoptNode(xmlDOMWrapCtxtPtr ctxt,
xmlNodePtr destParent,
int options)
{
if ((node == NULL) || (destDoc == NULL) ||
if ((node == NULL) || (node->type == XML_NAMESPACE_DECL) ||
(destDoc == NULL) ||
((destParent != NULL) && (destParent->doc != destDoc)))
return(-1);
/*

View File

@ -5236,7 +5236,7 @@ xmlValidateElementContent(xmlValidCtxtPtr ctxt, xmlNodePtr child,
xmlElementContentPtr cont;
const xmlChar *name;
if (elemDecl == NULL)
if ((elemDecl == NULL) || (parent == NULL))
return(-1);
cont = elemDecl->content;
name = elemDecl->name;
@ -5517,7 +5517,8 @@ xmlValidateOneCdataElement(xmlValidCtxtPtr ctxt, xmlDocPtr doc,
int ret = 1;
xmlNodePtr cur, child;
if ((ctxt == NULL) || (doc == NULL) || (elem == NULL))
if ((ctxt == NULL) || (doc == NULL) || (elem == NULL) ||
(elem->type != XML_ELEMENT_NODE))
return(0);
child = elem->children;
@ -6379,7 +6380,8 @@ xmlValidateElement(xmlValidCtxtPtr ctxt, xmlDocPtr doc, xmlNodePtr elem) {
* they don't really mean anything validation wise.
*/
if ((elem->type == XML_XINCLUDE_START) ||
(elem->type == XML_XINCLUDE_END))
(elem->type == XML_XINCLUDE_END) ||
(elem->type == XML_NAMESPACE_DECL))
return(1);
CHECK_DTD;

View File

@ -875,8 +875,8 @@ xmlXIncludeCopyNodeList(xmlXIncludeCtxtPtr ctxt, xmlDocPtr target,
static xmlNodePtr
xmlXIncludeGetNthChild(xmlNodePtr cur, int no) {
int i;
if (cur == NULL)
return(cur);
if ((cur == NULL) || (cur->type == XML_NAMESPACE_DECL))
return(NULL);
cur = cur->children;
for (i = 0;i <= no;cur = cur->next) {
if (cur == NULL)
@ -923,11 +923,13 @@ xmlXIncludeCopyRange(xmlXIncludeCtxtPtr ctxt, xmlDocPtr target,
return(NULL);
start = (xmlNodePtr) range->user;
if (start == NULL)
if ((start == NULL) || (start->type == XML_NAMESPACE_DECL))
return(NULL);
end = range->user2;
if (end == NULL)
return(xmlDocCopyNode(start, target, 1));
if (end->type == XML_NAMESPACE_DECL)
return(NULL);
cur = start;
index1 = range->index;
@ -1948,8 +1950,9 @@ static int
xmlXIncludeLoadFallback(xmlXIncludeCtxtPtr ctxt, xmlNodePtr fallback, int nr) {
xmlXIncludeCtxtPtr newctxt;
int ret = 0;
if ((fallback == NULL) || (ctxt == NULL))
if ((fallback == NULL) || (fallback->type == XML_NAMESPACE_DECL) ||
(ctxt == NULL))
return(-1);
if (fallback->children != NULL) {
/*
@ -2175,7 +2178,7 @@ xmlXIncludeIncludeNode(xmlXIncludeCtxtPtr ctxt, int nr) {
if ((nr < 0) || (nr >= ctxt->incNr))
return(-1);
cur = ctxt->incTab[nr]->ref;
if (cur == NULL)
if ((cur == NULL) || (cur->type == XML_NAMESPACE_DECL))
return(-1);
/*
@ -2350,7 +2353,7 @@ xmlXIncludeDoProcess(xmlXIncludeCtxtPtr ctxt, xmlDocPtr doc, xmlNodePtr tree) {
int ret = 0;
int i, start;
if ((doc == NULL) || (tree == NULL))
if ((doc == NULL) || (tree == NULL) || (tree->type == XML_NAMESPACE_DECL))
return(-1);
if (ctxt == NULL)
return(-1);
@ -2464,7 +2467,8 @@ xmlXIncludeProcessTreeFlagsData(xmlNodePtr tree, int flags, void *data) {
xmlXIncludeCtxtPtr ctxt;
int ret = 0;
if ((tree == NULL) || (tree->doc == NULL))
if ((tree == NULL) || (tree->type == XML_NAMESPACE_DECL) ||
(tree->doc == NULL))
return(-1);
ctxt = xmlXIncludeNewContext(tree->doc);
@ -2549,7 +2553,8 @@ xmlXIncludeProcessTreeFlags(xmlNodePtr tree, int flags) {
xmlXIncludeCtxtPtr ctxt;
int ret = 0;
if ((tree == NULL) || (tree->doc == NULL))
if ((tree == NULL) || (tree->type == XML_NAMESPACE_DECL) ||
(tree->doc == NULL))
return(-1);
ctxt = xmlXIncludeNewContext(tree->doc);
if (ctxt == NULL)
@ -2593,7 +2598,8 @@ int
xmlXIncludeProcessNode(xmlXIncludeCtxtPtr ctxt, xmlNodePtr node) {
int ret = 0;
if ((node == NULL) || (node->doc == NULL) || (ctxt == NULL))
if ((node == NULL) || (node->type == XML_NAMESPACE_DECL) ||
(node->doc == NULL) || (ctxt == NULL))
return(-1);
ret = xmlXIncludeDoProcess(ctxt, node->doc, node);
if ((ret >= 0) && (ctxt->nbErrors > 0))

View File

@ -1228,6 +1228,9 @@ xmlTextReaderCollectSiblings(xmlNodePtr node)
xmlBufferPtr buffer;
xmlChar *ret;
if ((node == NULL) || (node->type == XML_NAMESPACE_DECL))
return(NULL);
buffer = xmlBufferCreate();
if (buffer == NULL)
return NULL;

View File

@ -1465,6 +1465,10 @@ xhtmlNodeDumpOutput(xmlSaveCtxtPtr ctxt, xmlNodePtr cur) {
return;
if (cur->type == XML_XINCLUDE_END)
return;
if (cur->type == XML_NAMESPACE_DECL) {
xmlNsDumpOutputCtxt(ctxt, (xmlNsPtr) cur);
return;
}
if (cur->type == XML_DTD_NODE) {
xmlDtdDumpOutput(ctxt, (xmlDtdPtr) cur);
return;

13
xpath.c
View File

@ -7798,6 +7798,8 @@ xmlXPathNextDescendant(xmlXPathParserContextPtr ctxt, xmlNodePtr cur) {
return(ctxt->context->node->children);
}
if (cur->type == XML_NAMESPACE_DECL)
return(NULL);
if (cur->children != NULL) {
/*
* Do not descend on entities declarations
@ -8180,6 +8182,10 @@ xmlXPathNextFollowing(xmlXPathParserContextPtr ctxt, xmlNodePtr cur) {
static int
xmlXPathIsAncestor(xmlNodePtr ancestor, xmlNodePtr node) {
if ((ancestor == NULL) || (node == NULL)) return(0);
if (node->type == XML_NAMESPACE_DECL)
return(0);
if (ancestor->type == XML_NAMESPACE_DECL)
return(0);
/* nodes need to be in the same document */
if (ancestor->doc != node->doc) return(0);
/* avoid searching if ancestor or node is the root node */
@ -8217,7 +8223,7 @@ xmlXPathNextPreceding(xmlXPathParserContextPtr ctxt, xmlNodePtr cur)
if (cur->type == XML_ATTRIBUTE_NODE)
return(cur->parent);
}
if (cur == NULL)
if ((cur == NULL) || (cur->type == XML_NAMESPACE_DECL))
return (NULL);
if ((cur->prev != NULL) && (cur->prev->type == XML_DTD_NODE))
cur = cur->prev;
@ -8264,6 +8270,8 @@ xmlXPathNextPrecedingInternal(xmlXPathParserContextPtr ctxt,
return (NULL);
ctxt->ancestor = cur->parent;
}
if (cur->type == XML_NAMESPACE_DECL)
return(NULL);
if ((cur->prev != NULL) && (cur->prev->type == XML_DTD_NODE))
cur = cur->prev;
while (cur->prev == NULL) {
@ -8471,7 +8479,7 @@ xmlXPathCountFunction(xmlXPathParserContextPtr ctxt, int nargs) {
int i = 0;
tmp = cur->nodesetval->nodeTab[0];
if (tmp != NULL) {
if ((tmp != NULL) && (tmp->type != XML_NAMESPACE_DECL)) {
tmp = tmp->children;
while (tmp != NULL) {
tmp = tmp->next;
@ -14308,6 +14316,7 @@ next_node:
}
scan_children:
if (cur->type == XML_NAMESPACE_DECL) break;
if ((cur->children != NULL) && (depth < max_depth)) {
/*
* Do not descend on entities declarations

View File

@ -134,7 +134,7 @@ xmlNodePtr xmlXPtrAdvanceNode(xmlNodePtr cur, int *level);
static int
xmlXPtrGetArity(xmlNodePtr cur) {
int i;
if (cur == NULL)
if ((cur == NULL) || (cur->type == XML_NAMESPACE_DECL))
return(-1);
cur = cur->children;
for (i = 0;cur != NULL;cur = cur->next) {
@ -157,7 +157,7 @@ xmlXPtrGetArity(xmlNodePtr cur) {
static int
xmlXPtrGetIndex(xmlNodePtr cur) {
int i;
if (cur == NULL)
if ((cur == NULL) || (cur->type == XML_NAMESPACE_DECL))
return(-1);
for (i = 1;cur != NULL;cur = cur->prev) {
if ((cur->type == XML_ELEMENT_NODE) ||
@ -179,7 +179,7 @@ xmlXPtrGetIndex(xmlNodePtr cur) {
static xmlNodePtr
xmlXPtrGetNthChild(xmlNodePtr cur, int no) {
int i;
if (cur == NULL)
if ((cur == NULL) || (cur->type == XML_NAMESPACE_DECL))
return(cur);
cur = cur->children;
for (i = 0;i <= no;cur = cur->next) {
@ -1444,11 +1444,13 @@ xmlXPtrBuildRangeNodeList(xmlXPathObjectPtr range) {
return(NULL);
start = (xmlNodePtr) range->user;
if (start == NULL)
if ((start == NULL) || (start->type == XML_NAMESPACE_DECL))
return(NULL);
end = range->user2;
if (end == NULL)
return(xmlCopyNode(start, 1));
if (end->type == XML_NAMESPACE_DECL)
return(NULL);
cur = start;
index1 = range->index;
@ -2304,7 +2306,7 @@ xmlXPtrRangeToFunction(xmlXPathParserContextPtr ctxt, int nargs) {
xmlNodePtr
xmlXPtrAdvanceNode(xmlNodePtr cur, int *level) {
next:
if (cur == NULL)
if ((cur == NULL) || (cur->type == XML_NAMESPACE_DECL))
return(NULL);
if (cur->children != NULL) {
cur = cur->children ;
@ -2362,7 +2364,7 @@ xmlXPtrAdvanceChar(xmlNodePtr *node, int *indx, int bytes) {
if ((node == NULL) || (indx == NULL))
return(-1);
cur = *node;
if (cur == NULL)
if ((cur == NULL) || (cur->type == XML_NAMESPACE_DECL))
return(-1);
pos = *indx;
@ -2453,9 +2455,10 @@ xmlXPtrMatchString(const xmlChar *string, xmlNodePtr start, int startindex,
if (string == NULL)
return(-1);
if (start == NULL)
if ((start == NULL) || (start->type == XML_NAMESPACE_DECL))
return(-1);
if ((end == NULL) || (endindex == NULL))
if ((end == NULL) || (*end == NULL) ||
((*end)->type == XML_NAMESPACE_DECL) || (endindex == NULL))
return(-1);
cur = start;
if (cur == NULL)
@ -2538,13 +2541,12 @@ xmlXPtrSearchString(const xmlChar *string, xmlNodePtr *start, int *startindex,
if (string == NULL)
return(-1);
if ((start == NULL) || (startindex == NULL))
if ((start == NULL) || (*start == NULL) ||
((*start)->type == XML_NAMESPACE_DECL) || (startindex == NULL))
return(-1);
if ((end == NULL) || (endindex == NULL))
return(-1);
cur = *start;
if (cur == NULL)
return(-1);
pos = *startindex - 1;
first = string[0];
@ -2618,14 +2620,12 @@ xmlXPtrGetLastChar(xmlNodePtr *node, int *indx) {
xmlNodePtr cur;
int pos, len = 0;
if ((node == NULL) || (indx == NULL))
if ((node == NULL) || (*node == NULL) ||
((*node)->type == XML_NAMESPACE_DECL) || (indx == NULL))
return(-1);
cur = *node;
pos = *indx;
if (cur == NULL)
return(-1);
if ((cur->type == XML_ELEMENT_NODE) ||
(cur->type == XML_DOCUMENT_NODE) ||
(cur->type == XML_HTML_DOCUMENT_NODE)) {