X-Git-Url: http://v3vee.org/palacios/gitweb/gitweb.cgi?a=blobdiff_plain;f=palacios%2Fsrc%2Fpalacios%2Fvmm_xml.c;h=a797e639f5c970e89c5b7d0c814d812d954ff9ad;hb=4454a172129d12e97793c9c353339b85d3335af4;hp=d09a1760445e2d66717e8b9692906770d58e7d8c;hpb=93a8c8c46dc39c3994a8eec0076c28eb14a77da1;p=palacios.git diff --git a/palacios/src/palacios/vmm_xml.c b/palacios/src/palacios/vmm_xml.c index d09a176..a797e63 100644 --- a/palacios/src/palacios/vmm_xml.c +++ b/palacios/src/palacios/vmm_xml.c @@ -67,6 +67,7 @@ static void * tmp_realloc(void * old_ptr, size_t old_size, size_t new_size) { new_buf = V3_Malloc(new_size); if (new_buf == NULL) { + PrintError(VM_NONE, VCORE_NONE, "Cannot allocate in tmp_realloc in xml\n"); return NULL; } @@ -97,7 +98,7 @@ static void v3_xml_err(struct v3_xml_root * root, char * xml_str, const char * e vsnprintf(root->err, V3_XML_ERRL, fmt, ap); va_end(ap); - PrintError("XML Error: %s\n", root->err); + PrintError(VM_NONE, VCORE_NONE, "XML Error: %s\n", root->err); // free memory v3_xml_free(&(root->xml)); @@ -302,6 +303,12 @@ static void v3_xml_char_content(struct v3_xml_root * root, char * s, size_t len, char * tmp = NULL; tmp = V3_Malloc((l = strlen(xml->txt)) + len); + + if (!tmp) { + PrintError(VM_NONE, VCORE_NONE, "Cannot allocate in xml char content\n"); + return ; + } + strcpy(tmp, xml->txt); xml->txt = tmp; } @@ -362,6 +369,12 @@ static void v3_xml_free_attr(char **attr) { static struct v3_xml * v3_xml_new(const char * name) { struct v3_xml_root * root = (struct v3_xml_root *)V3_Malloc(sizeof(struct v3_xml_root)); + + if (!root) { + PrintError(VM_NONE, VCORE_NONE, "Cannot allocate in xml_new\n"); + return NULL; + } + memset(root, 0, sizeof(struct v3_xml_root)); root->xml.name = (char *)name; @@ -457,6 +470,12 @@ static struct v3_xml * v3_xml_add_child(struct v3_xml * xml, const char * name, } child = (struct v3_xml *)V3_Malloc(sizeof(struct v3_xml)); + + if (!child) { + PrintError(VM_NONE, VCORE_NONE, "Cannot allocate in xml_add_child\n"); + return NULL; + } + memset(child, 0, sizeof(struct v3_xml)); child->name = (char *)name; @@ -565,12 +584,31 @@ static struct v3_xml * parse_str(char * buf, size_t len) { ((attr_cnt * (2 * sizeof(char *))) + (2 * sizeof(char *)))); + if (!attr) { + PrintError(VM_NONE, VCORE_NONE, "Cannot reallocate in xml parse string\n"); + return NULL; + } + attr[last_idx] = tmp_realloc(attr[last_idx - 2], attr_cnt, (attr_cnt + 1)); + + if (!attr[last_idx]) { + PrintError(VM_NONE, VCORE_NONE, "Cannot reallocate in xml parse string\n"); + return NULL; + } + } else { attr = V3_Malloc(4 * sizeof(char *)); + if (!attr) { + PrintError(VM_NONE, VCORE_NONE, "Cannot allocate in xml parse string\n"); + return NULL; + } attr[last_idx] = V3_Malloc(2); + if (!attr[last_idx]) { + PrintError(VM_NONE, VCORE_NONE, "Cannot alloocate in xml parse string\n"); + return NULL; + } } attr[attr_idx] = buf; // set attribute name @@ -734,6 +772,12 @@ struct v3_xml * v3_xml_parse(char * buf) { str_len = strlen(buf); xml_buf = (char *)V3_Malloc(str_len + 1); + + if (!xml_buf) { + PrintError(VM_NONE, VCORE_NONE, "Cannot allocate in xml parse\n"); + return NULL; + } + strcpy(xml_buf, buf); return parse_str(xml_buf, str_len); @@ -825,10 +869,26 @@ struct v3_xml * v3_xml_set_attr(struct v3_xml * xml, const char * name, const ch // first attribute xml->attr = V3_Malloc(4 * sizeof(char *)); + if (!xml->attr) { + PrintError(VM_NONE, VCORE_NONE, "Cannot allocate in xml set attr\n"); + return NULL; + } + // empty list of malloced names/vals xml->attr[1] = strdup(""); + + if (!xml->attr[1]) { + PrintError(VM_NONE, VCORE_NONE, "Cannot strdup in xml set attr\n"); + return NULL; + } + } else { xml->attr = tmp_realloc(xml->attr, l * sizeof(char *), (l + 4) * sizeof(char *)); + + if (!xml->attr) { + PrintError(VM_NONE, VCORE_NONE, "Cannot reallocate in xml set attr\n"); + return NULL; + } } // set attribute name @@ -841,6 +901,12 @@ struct v3_xml * v3_xml_set_attr(struct v3_xml * xml, const char * name, const ch strlen(xml->attr[l + 1]), (c = strlen(xml->attr[l + 1])) + 2); + + if (!xml->attr[l + 3]) { + PrintError(VM_NONE, VCORE_NONE, "Cannot reallocate in xml set attr\n"); + return NULL; + } + // set name/value as not malloced strcpy(xml->attr[l + 3] + c, " "); @@ -1057,7 +1123,14 @@ char * v3_xml_tostr(struct v3_xml * xml) { struct v3_xml * o = (xml) ? xml->ordered : NULL; struct v3_xml_root * root = (struct v3_xml_root *)xml; size_t len = 0, max = V3_XML_BUFSIZE; - char *s = strcpy(V3_Malloc(max), ""); + char *s = V3_Malloc(max); + + if (!s) { + PrintError(VM_NONE, VCORE_NONE, "Cannot allocate in xml tostrr\n"); + return NULL; + } + + strcpy(s, ""); if (! xml || ! xml->name) return tmp_realloc(s, max, len + 1); while (root->xml.parent) root = (struct v3_xml_root *)root->xml.parent; // root tag