summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorDavid Sommerseth <davids@redhat.com>2010-04-20 12:08:04 +0200
committerDavid Sommerseth <davids@redhat.com>2010-04-20 12:08:04 +0200
commit63fa74b229dd25b1e6398f20b966725df855dcf3 (patch)
tree0d5e8a9f45358f245c87d51f9546be9926658eb4 /src
parent3aabb2ff8c7fdb9c68c38c2cdd13f64f7c74586d (diff)
downloadpython-dmidecode-63fa74b229dd25b1e6398f20b966725df855dcf3.tar.gz
python-dmidecode-63fa74b229dd25b1e6398f20b966725df855dcf3.tar.xz
python-dmidecode-63fa74b229dd25b1e6398f20b966725df855dcf3.zip
Allow format strings to be NULL in dmixml_Add*() functions
This bug was reported by Jan Hutaƙ <jhutar@redhat.com> [1] The implemented fix avoids assertions if the format strings to dmixml_AddAttribute(), dmixml_AddTextChild() and dmixml_AddTextContent() functions are NULL. In these cases, it will result in an empty value instead of returning NULL from these functions. [1] <https://bugzilla.redhat.com/show_bug.cgi?id=583867>
Diffstat (limited to 'src')
-rw-r--r--src/dmixml.c24
1 files changed, 19 insertions, 5 deletions
diff --git a/src/dmixml.c b/src/dmixml.c
index ba285e8..3b05ad4 100644
--- a/src/dmixml.c
+++ b/src/dmixml.c
@@ -92,13 +92,18 @@ xmlAttr *dmixml_AddAttribute(xmlNode *node, const char *atrname, const char *fmt
xmlAttr *res = NULL;
va_list ap;
- if( (node == NULL) || (atrname == NULL) || (fmt == NULL) ) {
+ if( (node == NULL) || (atrname == NULL) ) {
return NULL;
}
atrname_s = xmlCharStrdup(atrname);
assert( atrname_s != NULL );
+ if( fmt == NULL ) {
+ res = xmlNewProp(node, atrname_s, NULL);
+ goto exit;
+ }
+
va_start(ap, fmt);
val_s = dmixml_buildstr(2048, fmt, ap);
va_end(ap);
@@ -106,8 +111,9 @@ xmlAttr *dmixml_AddAttribute(xmlNode *node, const char *atrname, const char *fmt
res = xmlNewProp(node, atrname_s,
(xmlStrcmp(val_s, (xmlChar *) "(null)") == 0 ? NULL : val_s));
- free(atrname_s);
free(val_s);
+ exit:
+ free(atrname_s);
assert( res != NULL );
return res;
@@ -129,13 +135,18 @@ xmlNode *dmixml_AddTextChild(xmlNode *node, const char *tagname, const char *fmt
xmlNode *res = NULL;
va_list ap;
- if( (node == NULL) || (tagname == NULL) || (fmt == NULL) ) {
+ if( (node == NULL) || (tagname == NULL) ) {
return NULL;
}
tagname_s = xmlCharStrdup(tagname);
assert( tagname_s != NULL );
+ if( fmt == NULL ) {
+ res = xmlNewChild(node, NULL, tagname_s, NULL);
+ goto exit;
+ }
+
va_start(ap, fmt);
val_s = dmixml_buildstr(2048, fmt, ap);
va_end(ap);
@@ -144,8 +155,9 @@ xmlNode *dmixml_AddTextChild(xmlNode *node, const char *tagname, const char *fmt
res = xmlNewTextChild(node, NULL, tagname_s,
(xmlStrcmp(val_s, (xmlChar *) "(null)") == 0 ? NULL : val_s));
- free(tagname_s);
free(val_s);
+ exit:
+ free(tagname_s);
assert( res != NULL );
return res;
@@ -165,7 +177,9 @@ xmlNode *dmixml_AddTextContent(xmlNode *node, const char *fmt, ...)
va_list ap;
if( (node == NULL) || (fmt == NULL) ) {
- return NULL;
+ // Return node and not NULL, as node may not be NULL but fmt can be,
+ // thus doing a similar string check (val_s != "(null)") as later on
+ return node;
}
va_start(ap, fmt);