- Merge clang warning fix http://git.gnome.org/browse/libxml2/commit/?id=aae48e64dfbf2b46b157a4c1857e30645116388f
- Add a fix for proper escaping of xpointer expressions, commit upstream is pending.
- Add helper classes in chromium/libxml_utils.cc and chromium/include/libxml/libxml_utils.h.
+- Add a tweak to limit problems caused by excessive strings and buffers.
To import a new snapshot of libxml:
xmlReallocFunc xmlRealloc = (xmlReallocFunc) xmlMemRealloc;
xmlStrdupFunc xmlMemStrdup = (xmlStrdupFunc) xmlMemoryStrdup;
#else
+
+#define MAX_LIBXML_MALLOC (1024*1024*512)
+
+static void* size_checked_malloc(size_t size) {
+ if (size > MAX_LIBXML_MALLOC) {
+ *(volatile char*)0 = '\0';
+ return NULL;
+ }
+ return malloc(size);
+}
+
+static void* size_checked_realloc(void* ptr, size_t size) {
+ if (size > MAX_LIBXML_MALLOC) {
+ *(volatile char*)0 = '\0';
+ return NULL;
+ }
+ return realloc(ptr, size);
+}
+
/**
* xmlFree:
* @mem: an already allocated block of memory
*
* Returns a pointer to the newly allocated block or NULL in case of error
*/
-xmlMallocFunc xmlMalloc = (xmlMallocFunc) malloc;
+xmlMallocFunc xmlMalloc = (xmlMallocFunc) size_checked_malloc;
/**
* xmlMallocAtomic:
* @size: the size requested in bytes
*
* Returns a pointer to the newly allocated block or NULL in case of error
*/
-xmlMallocFunc xmlMallocAtomic = (xmlMallocFunc) malloc;
+xmlMallocFunc xmlMallocAtomic = (xmlMallocFunc) size_checked_malloc;
/**
* xmlRealloc:
* @mem: an already allocated block of memory
*
* Returns a pointer to the newly reallocated block or NULL in case of error
*/
-xmlReallocFunc xmlRealloc = (xmlReallocFunc) realloc;
+xmlReallocFunc xmlRealloc = (xmlReallocFunc) size_checked_realloc;
/**
* xmlMemStrdup:
* @str: a zero terminated string