|
|
1c8959 |
From b1a4e51efbfb1ae3a37a14be73d438aaab6b5c9e Mon Sep 17 00:00:00 2001
|
|
|
1c8959 |
From: Pranjal Jumde <pjumde@apple.com>
|
|
|
1c8959 |
Date: Tue, 8 Mar 2016 17:29:00 -0800
|
|
|
1c8959 |
Subject: [PATCH] Bug 763071: heap-buffer-overflow in xmlStrncat
|
|
|
1c8959 |
<https://bugzilla.gnome.org/show_bug.cgi?id=763071>
|
|
|
1c8959 |
To: libvir-list@redhat.com
|
|
|
1c8959 |
|
|
|
1c8959 |
* xmlstring.c:
|
|
|
1c8959 |
(xmlStrncat): Return NULL if xmlStrlen returns a negative length.
|
|
|
1c8959 |
(xmlStrncatNew): Ditto.
|
|
|
1c8959 |
|
|
|
1c8959 |
Signed-off-by: Daniel Veillard <veillard@redhat.com>
|
|
|
1c8959 |
---
|
|
|
1c8959 |
xmlstring.c | 9 ++++++++-
|
|
|
1c8959 |
1 file changed, 8 insertions(+), 1 deletion(-)
|
|
|
1c8959 |
|
|
|
1c8959 |
diff --git a/xmlstring.c b/xmlstring.c
|
|
|
1c8959 |
index a37220d..d465c23 100644
|
|
|
1c8959 |
--- a/xmlstring.c
|
|
|
1c8959 |
+++ b/xmlstring.c
|
|
|
1c8959 |
@@ -457,6 +457,8 @@ xmlStrncat(xmlChar *cur, const xmlChar *add, int len) {
|
|
|
1c8959 |
return(xmlStrndup(add, len));
|
|
|
1c8959 |
|
|
|
1c8959 |
size = xmlStrlen(cur);
|
|
|
1c8959 |
+ if (size < 0)
|
|
|
1c8959 |
+ return(NULL);
|
|
|
1c8959 |
ret = (xmlChar *) xmlRealloc(cur, (size + len + 1) * sizeof(xmlChar));
|
|
|
1c8959 |
if (ret == NULL) {
|
|
|
1c8959 |
xmlErrMemory(NULL, NULL);
|
|
|
1c8959 |
@@ -484,14 +486,19 @@ xmlStrncatNew(const xmlChar *str1, const xmlChar *str2, int len) {
|
|
|
1c8959 |
int size;
|
|
|
1c8959 |
xmlChar *ret;
|
|
|
1c8959 |
|
|
|
1c8959 |
- if (len < 0)
|
|
|
1c8959 |
+ if (len < 0) {
|
|
|
1c8959 |
len = xmlStrlen(str2);
|
|
|
1c8959 |
+ if (len < 0)
|
|
|
1c8959 |
+ return(NULL);
|
|
|
1c8959 |
+ }
|
|
|
1c8959 |
if ((str2 == NULL) || (len == 0))
|
|
|
1c8959 |
return(xmlStrdup(str1));
|
|
|
1c8959 |
if (str1 == NULL)
|
|
|
1c8959 |
return(xmlStrndup(str2, len));
|
|
|
1c8959 |
|
|
|
1c8959 |
size = xmlStrlen(str1);
|
|
|
1c8959 |
+ if (size < 0)
|
|
|
1c8959 |
+ return(NULL);
|
|
|
1c8959 |
ret = (xmlChar *) xmlMalloc((size + len + 1) * sizeof(xmlChar));
|
|
|
1c8959 |
if (ret == NULL) {
|
|
|
1c8959 |
xmlErrMemory(NULL, NULL);
|
|
|
1c8959 |
--
|
|
|
1c8959 |
2.5.5
|
|
|
1c8959 |
|