libxml2 r3740 - trunk



Author: veillard
Date: Thu Apr 24 11:58:41 2008
New Revision: 3740
URL: http://svn.gnome.org/viewvc/libxml2?rev=3740&view=rev

Log:
* uri.c: applied patch from Ashwin fixing a number of realloc problems
* HTMLparser.c: improve handling for misplaced html/head/body
Daniel


Modified:
   trunk/ChangeLog
   trunk/HTMLparser.c
   trunk/uri.c

Modified: trunk/HTMLparser.c
==============================================================================
--- trunk/HTMLparser.c	(original)
+++ trunk/HTMLparser.c	Thu Apr 24 11:58:41 2008
@@ -3482,6 +3482,7 @@
 	             "htmlParseStartTag: misplaced <html> tag\n",
 		     name, NULL);
 	discardtag = 1;
+	ctxt->depth++;
     }
     if ((ctxt->nameNr != 1) && 
 	(xmlStrEqual(name, BAD_CAST"head"))) {
@@ -3489,6 +3490,7 @@
 	             "htmlParseStartTag: misplaced <head> tag\n",
 		     name, NULL);
 	discardtag = 1;
+	ctxt->depth++;
     }
     if (xmlStrEqual(name, BAD_CAST"body")) {
 	int indx;
@@ -3498,6 +3500,7 @@
 		             "htmlParseStartTag: misplaced <body> tag\n",
 			     name, NULL);
 		discardtag = 1;
+		ctxt->depth++;
 	    }
 	}
     }
@@ -3648,7 +3651,6 @@
     name = htmlParseHTMLName(ctxt);
     if (name == NULL)
         return (0);
-
     /*
      * We should definitely be at the ending "S? '>'" part
      */
@@ -3669,6 +3671,18 @@
         NEXT;
 
     /*
+     * if we ignored misplaced tags in htmlParseStartTag don't pop them
+     * out now.
+     */
+    if ((ctxt->depth > 0) &&
+        (xmlStrEqual(name, BAD_CAST "html") ||
+         xmlStrEqual(name, BAD_CAST "body") ||
+	 xmlStrEqual(name, BAD_CAST "head"))) {
+	ctxt->depth--;
+	return (0);
+    }
+
+    /*
      * If the name read is not one of the element in the parsing stack
      * then return, it's just an error.
      */

Modified: trunk/uri.c
==============================================================================
--- trunk/uri.c	(original)
+++ trunk/uri.c	Thu Apr 24 11:58:41 2008
@@ -225,6 +225,7 @@
 xmlChar *
 xmlSaveUri(xmlURIPtr uri) {
     xmlChar *ret = NULL;
+    xmlChar *temp;
     const char *p;
     int len;
     int max;
@@ -246,23 +247,27 @@
 	while (*p != 0) {
 	    if (len >= max) {
 		max *= 2;
-		ret = (xmlChar *) xmlRealloc(ret, (max + 1) * sizeof(xmlChar));
-		if (ret == NULL) {
+		temp = (xmlChar *) xmlRealloc(ret, (max + 1) * sizeof(xmlChar));
+		if (temp == NULL) {
 		    xmlGenericError(xmlGenericErrorContext,
 			    "xmlSaveUri: out of memory\n");
+		    xmlFree(ret);
 		    return(NULL);
 		}
+		ret = temp;
 	    }
 	    ret[len++] = *p++;
 	}
 	if (len >= max) {
 	    max *= 2;
-	    ret = (xmlChar *) xmlRealloc(ret, (max + 1) * sizeof(xmlChar));
-	    if (ret == NULL) {
+	    temp = (xmlChar *) xmlRealloc(ret, (max + 1) * sizeof(xmlChar));
+	    if (temp == NULL) {
 		xmlGenericError(xmlGenericErrorContext,
 			"xmlSaveUri: out of memory\n");
+		xmlFree(ret);
 		return(NULL);
 	    }
+	    ret = temp;
 	}
 	ret[len++] = ':';
     }
@@ -271,12 +276,14 @@
 	while (*p != 0) {
 	    if (len + 3 >= max) {
 		max *= 2;
-		ret = (xmlChar *) xmlRealloc(ret, (max + 1) * sizeof(xmlChar));
-		if (ret == NULL) {
+		temp = (xmlChar *) xmlRealloc(ret, (max + 1) * sizeof(xmlChar));
+		if (temp == NULL) {
 		    xmlGenericError(xmlGenericErrorContext,
 			    "xmlSaveUri: out of memory\n");
+		    xmlFree(ret);
 		    return(NULL);
 		}
+		ret = temp;
 	    }
 	    if (IS_RESERVED(*(p)) || IS_UNRESERVED(*(p)))
 		ret[len++] = *p++;
@@ -292,12 +299,14 @@
 	if (uri->server != NULL) {
 	    if (len + 3 >= max) {
 		max *= 2;
-		ret = (xmlChar *) xmlRealloc(ret, (max + 1) * sizeof(xmlChar));
-		if (ret == NULL) {
+		temp = (xmlChar *) xmlRealloc(ret, (max + 1) * sizeof(xmlChar));
+		if (temp == NULL) {
 		    xmlGenericError(xmlGenericErrorContext,
 			    "xmlSaveUri: out of memory\n");
+                  xmlFree(ret);  
 		    return(NULL);
 		}
+		ret = temp;
 	    }
 	    ret[len++] = '/';
 	    ret[len++] = '/';
@@ -306,13 +315,15 @@
 		while (*p != 0) {
 		    if (len + 3 >= max) {
 			max *= 2;
-			ret = (xmlChar *) xmlRealloc(ret,
+			temp = (xmlChar *) xmlRealloc(ret,
 				(max + 1) * sizeof(xmlChar));
-			if (ret == NULL) {
+			if (temp == NULL) {
 			    xmlGenericError(xmlGenericErrorContext,
 				    "xmlSaveUri: out of memory\n");
+			    xmlFree(ret);
 			    return(NULL);
 			}
+			ret = temp;
 		    }
 		    if ((IS_UNRESERVED(*(p))) ||
 			((*(p) == ';')) || ((*(p) == ':')) ||
@@ -330,13 +341,15 @@
 		}
 		if (len + 3 >= max) {
 		    max *= 2;
-		    ret = (xmlChar *) xmlRealloc(ret,
+		    temp = (xmlChar *) xmlRealloc(ret,
 			    (max + 1) * sizeof(xmlChar));
-		    if (ret == NULL) {
+		    if (temp == NULL) {
 			xmlGenericError(xmlGenericErrorContext,
 				"xmlSaveUri: out of memory\n");
+			xmlFree(ret);
 			return(NULL);
 		    }
+		    ret = temp;
 		}
 		ret[len++] = '@';
 	    }
@@ -344,39 +357,45 @@
 	    while (*p != 0) {
 		if (len >= max) {
 		    max *= 2;
-		    ret = (xmlChar *) xmlRealloc(ret,
+		    temp = (xmlChar *) xmlRealloc(ret,
 			    (max + 1) * sizeof(xmlChar));
-		    if (ret == NULL) {
+		    if (temp == NULL) {
 			xmlGenericError(xmlGenericErrorContext,
 				"xmlSaveUri: out of memory\n");
+			xmlFree(ret);
 			return(NULL);
 		    }
+		    ret = temp;
 		}
 		ret[len++] = *p++;
 	    }
 	    if (uri->port > 0) {
 		if (len + 10 >= max) {
 		    max *= 2;
-		    ret = (xmlChar *) xmlRealloc(ret,
+		    temp = (xmlChar *) xmlRealloc(ret,
 			    (max + 1) * sizeof(xmlChar));
-		    if (ret == NULL) {
+		    if (temp == NULL) {
 			xmlGenericError(xmlGenericErrorContext,
 				"xmlSaveUri: out of memory\n");
+                     xmlFree(ret);
 			return(NULL);
 		    }
+		    ret = temp;
 		}
 		len += snprintf((char *) &ret[len], max - len, ":%d", uri->port);
 	    }
 	} else if (uri->authority != NULL) {
 	    if (len + 3 >= max) {
 		max *= 2;
-		ret = (xmlChar *) xmlRealloc(ret,
+		temp = (xmlChar *) xmlRealloc(ret,
 			(max + 1) * sizeof(xmlChar));
-		if (ret == NULL) {
-		    xmlGenericError(xmlGenericErrorContext,
-			    "xmlSaveUri: out of memory\n");
-		    return(NULL);
-		}
+		if (temp == NULL) {
+			xmlGenericError(xmlGenericErrorContext,
+				"xmlSaveUri: out of memory\n");
+                     xmlFree(ret);
+			return(NULL);
+		    }
+		    ret = temp;
 	    }
 	    ret[len++] = '/';
 	    ret[len++] = '/';
@@ -384,13 +403,15 @@
 	    while (*p != 0) {
 		if (len + 3 >= max) {
 		    max *= 2;
-		    ret = (xmlChar *) xmlRealloc(ret,
+		    temp = (xmlChar *) xmlRealloc(ret,
 			    (max + 1) * sizeof(xmlChar));
-		    if (ret == NULL) {
+		    if (temp == NULL) {
 			xmlGenericError(xmlGenericErrorContext,
 				"xmlSaveUri: out of memory\n");
+                     xmlFree(ret);
 			return(NULL);
 		    }
+		    ret = temp;
 		}
 		if ((IS_UNRESERVED(*(p))) ||
                     ((*(p) == '$')) || ((*(p) == ',')) || ((*(p) == ';')) ||
@@ -408,13 +429,15 @@
 	} else if (uri->scheme != NULL) {
 	    if (len + 3 >= max) {
 		max *= 2;
-		ret = (xmlChar *) xmlRealloc(ret,
+		temp = (xmlChar *) xmlRealloc(ret,
 			(max + 1) * sizeof(xmlChar));
-		if (ret == NULL) {
-		    xmlGenericError(xmlGenericErrorContext,
-			    "xmlSaveUri: out of memory\n");
-		    return(NULL);
-		}
+		if (temp == NULL) {
+			xmlGenericError(xmlGenericErrorContext,
+				"xmlSaveUri: out of memory\n");
+                     xmlFree(ret);
+			return(NULL);
+		    }
+		    ret = temp;
 	    }
 	    ret[len++] = '/';
 	    ret[len++] = '/';
@@ -448,13 +471,15 @@
 	    while (*p != 0) {
 		if (len + 3 >= max) {
 		    max *= 2;
-		    ret = (xmlChar *) xmlRealloc(ret,
+		    temp = (xmlChar *) xmlRealloc(ret,
 			    (max + 1) * sizeof(xmlChar));
-		    if (ret == NULL) {
+		    if (temp == NULL) {
 			xmlGenericError(xmlGenericErrorContext,
 				"xmlSaveUri: out of memory\n");
+                     xmlFree(ret);
 			return(NULL);
 		    }
+		    ret = temp;
 		}
 		if ((IS_UNRESERVED(*(p))) || ((*(p) == '/')) ||
                     ((*(p) == ';')) || ((*(p) == '@')) || ((*(p) == '&')) ||
@@ -473,52 +498,60 @@
 	if (uri->query_raw != NULL) {
 	    if (len + 1 >= max) {
 		max *= 2;
-		ret = (xmlChar *) xmlRealloc(ret,
+		temp = (xmlChar *) xmlRealloc(ret,
 			(max + 1) * sizeof(xmlChar));
-		if (ret == NULL) {
-		    xmlGenericError(xmlGenericErrorContext,
-			    "xmlSaveUri: out of memory\n");
-		    return(NULL);
-		}
+		if (temp == NULL) {
+			xmlGenericError(xmlGenericErrorContext,
+				"xmlSaveUri: out of memory\n");
+                     xmlFree(ret);
+			return(NULL);
+		    }
+		    ret = temp;
 	    }
 	    ret[len++] = '?';
 	    p = uri->query_raw;
 	    while (*p != 0) {
 		if (len + 1 >= max) {
 		    max *= 2;
-		    ret = (xmlChar *) xmlRealloc(ret,
+		    temp = (xmlChar *) xmlRealloc(ret,
 			    (max + 1) * sizeof(xmlChar));
-		    if (ret == NULL) {
+		    if (temp == NULL) {
 			xmlGenericError(xmlGenericErrorContext,
 				"xmlSaveUri: out of memory\n");
+                     xmlFree(ret);
 			return(NULL);
 		    }
+		    ret = temp;
 		}
 		ret[len++] = *p++;
 	    }
 	} else if (uri->query != NULL) {
 	    if (len + 3 >= max) {
 		max *= 2;
-		ret = (xmlChar *) xmlRealloc(ret,
+		temp = (xmlChar *) xmlRealloc(ret,
 			(max + 1) * sizeof(xmlChar));
-		if (ret == NULL) {
-		    xmlGenericError(xmlGenericErrorContext,
-			    "xmlSaveUri: out of memory\n");
-		    return(NULL);
-		}
+		if (temp == NULL) {
+			xmlGenericError(xmlGenericErrorContext,
+				"xmlSaveUri: out of memory\n");
+                     xmlFree(ret);
+			return(NULL);
+		    }
+		    ret = temp;
 	    }
 	    ret[len++] = '?';
 	    p = uri->query;
 	    while (*p != 0) {
 		if (len + 3 >= max) {
 		    max *= 2;
-		    ret = (xmlChar *) xmlRealloc(ret,
+		    temp = (xmlChar *) xmlRealloc(ret,
 			    (max + 1) * sizeof(xmlChar));
-		    if (ret == NULL) {
+		    if (temp == NULL) {
 			xmlGenericError(xmlGenericErrorContext,
 				"xmlSaveUri: out of memory\n");
+                     xmlFree(ret);
 			return(NULL);
 		    }
+		    ret = temp;
 		}
 		if ((IS_UNRESERVED(*(p))) || (IS_RESERVED(*(p)))) 
 		    ret[len++] = *p++;
@@ -535,26 +568,30 @@
     if (uri->fragment != NULL) {
 	if (len + 3 >= max) {
 	    max *= 2;
-	    ret = (xmlChar *) xmlRealloc(ret,
+	    temp = (xmlChar *) xmlRealloc(ret,
 		    (max + 1) * sizeof(xmlChar));
-	    if (ret == NULL) {
-		xmlGenericError(xmlGenericErrorContext,
-			"xmlSaveUri: out of memory\n");
-		return(NULL);
-	    }
+	    if (temp == NULL) {
+			xmlGenericError(xmlGenericErrorContext,
+				"xmlSaveUri: out of memory\n");
+                     xmlFree(ret);
+			return(NULL);
+        	    }
+        	    ret = temp;
 	}
 	ret[len++] = '#';
 	p = uri->fragment;
 	while (*p != 0) {
 	    if (len + 3 >= max) {
 		max *= 2;
-		ret = (xmlChar *) xmlRealloc(ret,
+		temp = (xmlChar *) xmlRealloc(ret,
 			(max + 1) * sizeof(xmlChar));
-		if (ret == NULL) {
-		    xmlGenericError(xmlGenericErrorContext,
-			    "xmlSaveUri: out of memory\n");
-		    return(NULL);
-		}
+		if (temp == NULL) {
+			xmlGenericError(xmlGenericErrorContext,
+				"xmlSaveUri: out of memory\n");
+                     xmlFree(ret);
+			return(NULL);
+		    }
+		    ret = temp;
 	    }
 	    if ((IS_UNRESERVED(*(p))) || (IS_RESERVED(*(p)))) 
 		ret[len++] = *p++;
@@ -569,12 +606,14 @@
     }
     if (len >= max) {
 	max *= 2;
-	ret = (xmlChar *) xmlRealloc(ret, (max + 1) * sizeof(xmlChar));
-	if (ret == NULL) {
-	    xmlGenericError(xmlGenericErrorContext,
-		    "xmlSaveUri: out of memory\n");
-	    return(NULL);
-	}
+	temp = (xmlChar *) xmlRealloc(ret, (max + 1) * sizeof(xmlChar));
+	if (temp == NULL) {
+			xmlGenericError(xmlGenericErrorContext,
+				"xmlSaveUri: out of memory\n");
+                     xmlFree(ret);
+			return(NULL);
+		    }
+		    ret = temp;
     }
     ret[len++] = 0;
     return(ret);
@@ -928,6 +967,7 @@
 xmlChar *
 xmlURIEscapeStr(const xmlChar *str, const xmlChar *list) {
     xmlChar *ret, ch;
+    xmlChar *temp;
     const xmlChar *in;
 
     unsigned int len, out;
@@ -951,12 +991,14 @@
     while(*in != 0) {
 	if (len - out <= 3) {
 	    len += 20;
-	    ret = (xmlChar *) xmlRealloc(ret, len);
-	    if (ret == NULL) {
+	    temp = (xmlChar *) xmlRealloc(ret, len);
+	    if (temp == NULL) {
 		xmlGenericError(xmlGenericErrorContext,
 			"xmlURIEscapeStr: out of memory\n");
+		xmlFree(ret);
 		return(NULL);
 	    }
+	    ret = temp;
 	}
 
 	ch = *in;
@@ -1009,7 +1051,8 @@
 #define NULLCHK(p) if(!p) { \
                    xmlGenericError(xmlGenericErrorContext, \
                         "xmlURIEscape: out of memory\n"); \
-                   return NULL; }
+                        xmlFreeURI(uri); \
+                        return NULL; } \
 
     if (str == NULL)
         return (NULL);



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]