[libxml2] A few more safety cleanup raised by scan
- From: Daniel Veillard <veillard src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [libxml2] A few more safety cleanup raised by scan
- Date: Mon, 7 Sep 2009 10:17:29 +0000 (UTC)
commit d44b9364991bd0067d50c29bdff48305dfdad4ce
Author: Daniel Veillard <veillard redhat com>
Date: Mon Sep 7 12:15:08 2009 +0200
A few more safety cleanup raised by scan
* SAX2.c encoding.c parser.c xmlschemas.c: a few more safety checks
* relaxng.c: remove an unused intitialization
SAX2.c | 40 +++++++++++++++++++++-------------------
encoding.c | 15 +++++++++------
parser.c | 21 ++++++++++++++++-----
relaxng.c | 5 ++++-
xmlschemas.c | 3 ++-
5 files changed, 52 insertions(+), 32 deletions(-)
---
diff --git a/SAX2.c b/SAX2.c
index 94b39d4..1cf186a 100644
--- a/SAX2.c
+++ b/SAX2.c
@@ -1246,30 +1246,32 @@ xmlSAX2AttributeInternal(void *ctx, const xmlChar *fullname,
}
if (ns != NULL) {
- xmlAttrPtr prop;
namespace = xmlSearchNs(ctxt->myDoc, ctxt->node, ns);
+
if (namespace == NULL) {
xmlNsErrMsg(ctxt, XML_NS_ERR_UNDEFINED_NAMESPACE,
"Namespace prefix %s of attribute %s is not defined\n",
ns, name);
- }
-
- prop = ctxt->node->properties;
- while (prop != NULL) {
- if (prop->ns != NULL) {
- if ((xmlStrEqual(name, prop->name)) &&
- ((namespace == prop->ns) ||
- (xmlStrEqual(namespace->href, prop->ns->href)))) {
- xmlNsErrMsg(ctxt, XML_ERR_ATTRIBUTE_REDEFINED,
- "Attribute %s in %s redefined\n",
- name, namespace->href);
- ctxt->wellFormed = 0;
- if (ctxt->recovery == 0) ctxt->disableSAX = 1;
- goto error;
- }
- }
- prop = prop->next;
- }
+ } else {
+ xmlAttrPtr prop;
+
+ prop = ctxt->node->properties;
+ while (prop != NULL) {
+ if (prop->ns != NULL) {
+ if ((xmlStrEqual(name, prop->name)) &&
+ ((namespace == prop->ns) ||
+ (xmlStrEqual(namespace->href, prop->ns->href)))) {
+ xmlNsErrMsg(ctxt, XML_ERR_ATTRIBUTE_REDEFINED,
+ "Attribute %s in %s redefined\n",
+ name, namespace->href);
+ ctxt->wellFormed = 0;
+ if (ctxt->recovery == 0) ctxt->disableSAX = 1;
+ goto error;
+ }
+ }
+ prop = prop->next;
+ }
+ }
} else {
namespace = NULL;
}
diff --git a/encoding.c b/encoding.c
index d48c757..b86a547 100644
--- a/encoding.c
+++ b/encoding.c
@@ -1602,14 +1602,17 @@ xmlFindCharEncodingHandler(const char *name) {
}
upper[i] = 0;
- for (i = 0;i < nbCharEncodingHandler; i++)
- if (!strcmp(upper, handlers[i]->name)) {
+ if (handlers != NULL) {
+ for (i = 0;i < nbCharEncodingHandler; i++) {
+ if (!strcmp(upper, handlers[i]->name)) {
#ifdef DEBUG_ENCODING
- xmlGenericError(xmlGenericErrorContext,
- "Found registered handler for encoding %s\n", name);
+ xmlGenericError(xmlGenericErrorContext,
+ "Found registered handler for encoding %s\n", name);
#endif
- return(handlers[i]);
- }
+ return(handlers[i]);
+ }
+ }
+ }
#ifdef LIBXML_ICONV_ENABLED
/* check whether iconv can handle this */
diff --git a/parser.c b/parser.c
index 5337541..1e4164a 100644
--- a/parser.c
+++ b/parser.c
@@ -524,13 +524,21 @@ xmlWarningMsg(xmlParserCtxtPtr ctxt, xmlParserErrors error,
if ((ctxt != NULL) && (ctxt->sax != NULL) &&
(ctxt->sax->initialized == XML_SAX2_MAGIC))
schannel = ctxt->sax->serror;
- __xmlRaiseError(schannel,
+ if (ctxt != NULL) {
+ __xmlRaiseError(schannel,
(ctxt->sax) ? ctxt->sax->warning : NULL,
ctxt->userData,
ctxt, NULL, XML_FROM_PARSER, error,
XML_ERR_WARNING, NULL, 0,
(const char *) str1, (const char *) str2, NULL, 0, 0,
msg, (const char *) str1, (const char *) str2);
+ } else {
+ __xmlRaiseError(schannel, NULL, NULL,
+ ctxt, NULL, XML_FROM_PARSER, error,
+ XML_ERR_WARNING, NULL, 0,
+ (const char *) str1, (const char *) str2, NULL, 0, 0,
+ msg, (const char *) str1, (const char *) str2);
+ }
}
/**
@@ -5773,7 +5781,8 @@ xmlParseElementMixedContentDecl(xmlParserCtxtPtr ctxt, int inputchk) {
if (cur->c2 != NULL)
cur->c2->parent = cur;
}
- ret->ocur = XML_ELEMENT_CONTENT_MULT;
+ if (ret != NULL)
+ ret->ocur = XML_ELEMENT_CONTENT_MULT;
if ((ctxt->validate) && (ctxt->input->id != inputchk)) {
xmlValidityError(ctxt, XML_ERR_ENTITY_BOUNDARY,
"Element content declaration doesn't start and stop in the same entity\n",
@@ -8370,7 +8379,7 @@ xmlParseQName(xmlParserCtxtPtr ctxt, const xmlChar **prefix) {
static const xmlChar *
xmlParseQNameAndCompare(xmlParserCtxtPtr ctxt, xmlChar const *name,
xmlChar const *prefix) {
- const xmlChar *cmp = name;
+ const xmlChar *cmp;
const xmlChar *in;
const xmlChar *ret;
const xmlChar *prefix2;
@@ -8379,7 +8388,7 @@ xmlParseQNameAndCompare(xmlParserCtxtPtr ctxt, xmlChar const *name,
GROW;
in = ctxt->input->cur;
-
+
cmp = prefix;
while (*in != 0 && *in == *cmp) {
++in;
@@ -12768,7 +12777,9 @@ xmlParseBalancedChunkMemoryInternal(xmlParserCtxtPtr oldctxt,
* Record in the parent context the number of entities replacement
* done when parsing that reference.
*/
- oldctxt->nbentities += ctxt->nbentities;
+ if (oldctxt != NULL)
+ oldctxt->nbentities += ctxt->nbentities;
+
/*
* Also record the last error if any
*/
diff --git a/relaxng.c b/relaxng.c
index 351f03a..5146d9d 100644
--- a/relaxng.c
+++ b/relaxng.c
@@ -3470,6 +3470,9 @@ xmlRelaxNGGetDataTypeLibrary(xmlRelaxNGParserCtxtPtr ctxt ATTRIBUTE_UNUSED,
{
xmlChar *ret, *escape;
+ if (node == NULL)
+ return(NULL);
+
if ((IS_RELAXNG(node, "data")) || (IS_RELAXNG(node, "value"))) {
ret = xmlGetProp(node, BAD_CAST "datatypeLibrary");
if (ret != NULL) {
@@ -6229,7 +6232,7 @@ xmlRelaxNGCheckRules(xmlRelaxNGParserCtxtPtr ctxt,
xmlRelaxNGDefinePtr cur, int flags,
xmlRelaxNGType ptype)
{
- int nflags = flags;
+ int nflags;
xmlRelaxNGContentType ret, tmp, val = XML_RELAXNG_CONTENT_EMPTY;
while (cur != NULL) {
diff --git a/xmlschemas.c b/xmlschemas.c
index e79d5a0..acc1f78 100644
--- a/xmlschemas.c
+++ b/xmlschemas.c
@@ -15635,7 +15635,8 @@ xmlSchemaCheckCOSSTRestricts(xmlSchemaParserCtxtPtr pctxt,
return (XML_SCHEMAP_COS_ST_RESTRICTS_3_3_2_3);
}
member = member->next;
- baseMember = baseMember->next;
+ if (baseMember != NULL)
+ baseMember = baseMember->next;
}
}
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]