|
|
c55d09 |
From 0a742856490bfdcb02c2af48a2a849593cccf1c7 Mon Sep 17 00:00:00 2001
|
|
|
c55d09 |
From: Viktor Mihajlovski <mihajlov@linux.vnet.ibm.com>
|
|
|
c55d09 |
Date: Thu, 29 Aug 2013 17:18:49 +0200
|
|
|
c55d09 |
Subject: [PATCH 08/48] libxkutil: Improve domain.os_info cleanup
|
|
|
c55d09 |
|
|
|
c55d09 |
The union fields in os_info were set by means of XML parsing which
|
|
|
c55d09 |
doesn't take into account that certain fields are depending on the
|
|
|
c55d09 |
virtualization type.
|
|
|
c55d09 |
This could lead both to memory overwrites and memory leaks.
|
|
|
c55d09 |
Fixed by using temporary variables and type-based setting of fields
|
|
|
c55d09 |
|
|
|
c55d09 |
Signed-off-by: Viktor Mihajlovski <mihajlov@linux.vnet.ibm.com>
|
|
|
c55d09 |
Signed-off-by: John Ferlan <jferlan@redhat.com>
|
|
|
c55d09 |
---
|
|
|
c55d09 |
libxkutil/device_parsing.c | 73 +++++++++++++++++++++++++++++++++-------------
|
|
|
c55d09 |
1 file changed, 52 insertions(+), 21 deletions(-)
|
|
|
c55d09 |
|
|
|
c55d09 |
diff --git a/libxkutil/device_parsing.c b/libxkutil/device_parsing.c
|
|
|
c55d09 |
index 542e4e9..ad0f19c 100644
|
|
|
c55d09 |
--- a/libxkutil/device_parsing.c
|
|
|
c55d09 |
+++ b/libxkutil/device_parsing.c
|
|
|
c55d09 |
@@ -1103,23 +1103,37 @@ int parse_fq_devid(const char *devid, char **host, char **device)
|
|
|
c55d09 |
return 1;
|
|
|
c55d09 |
}
|
|
|
c55d09 |
|
|
|
c55d09 |
+static void cleanup_bootlist(char **blist, unsigned blist_ct)
|
|
|
c55d09 |
+{
|
|
|
c55d09 |
+ while (blist_ct > 0) {
|
|
|
c55d09 |
+ free(blist[--blist_ct]);
|
|
|
c55d09 |
+ }
|
|
|
c55d09 |
+ free(blist);
|
|
|
c55d09 |
+}
|
|
|
c55d09 |
+
|
|
|
c55d09 |
static int parse_os(struct domain *dominfo, xmlNode *os)
|
|
|
c55d09 |
{
|
|
|
c55d09 |
xmlNode *child;
|
|
|
c55d09 |
char **blist = NULL;
|
|
|
c55d09 |
unsigned bl_size = 0;
|
|
|
c55d09 |
+ char *kernel = NULL;
|
|
|
c55d09 |
+ char *initrd = NULL;
|
|
|
c55d09 |
+ char *cmdline = NULL;
|
|
|
c55d09 |
+ char *loader = NULL;
|
|
|
c55d09 |
+ char *boot = NULL;
|
|
|
c55d09 |
+ char *init = NULL;
|
|
|
c55d09 |
|
|
|
c55d09 |
for (child = os->children; child != NULL; child = child->next) {
|
|
|
c55d09 |
- if (XSTREQ(child->name, "type"))
|
|
|
c55d09 |
+ if (XSTREQ(child->name, "type")) {
|
|
|
c55d09 |
STRPROP(dominfo, os_info.pv.type, child);
|
|
|
c55d09 |
- else if (XSTREQ(child->name, "kernel"))
|
|
|
c55d09 |
- STRPROP(dominfo, os_info.pv.kernel, child);
|
|
|
c55d09 |
+ } else if (XSTREQ(child->name, "kernel"))
|
|
|
c55d09 |
+ kernel = get_node_content(child);
|
|
|
c55d09 |
else if (XSTREQ(child->name, "initrd"))
|
|
|
c55d09 |
- STRPROP(dominfo, os_info.pv.initrd, child);
|
|
|
c55d09 |
+ initrd = get_node_content(child);
|
|
|
c55d09 |
else if (XSTREQ(child->name, "cmdline"))
|
|
|
c55d09 |
- STRPROP(dominfo, os_info.pv.cmdline, child);
|
|
|
c55d09 |
+ cmdline = get_node_content(child);
|
|
|
c55d09 |
else if (XSTREQ(child->name, "loader"))
|
|
|
c55d09 |
- STRPROP(dominfo, os_info.fv.loader, child);
|
|
|
c55d09 |
+ loader = get_node_content(child);
|
|
|
c55d09 |
else if (XSTREQ(child->name, "boot")) {
|
|
|
c55d09 |
char **tmp_list = NULL;
|
|
|
c55d09 |
|
|
|
c55d09 |
@@ -1137,7 +1151,7 @@ static int parse_os(struct domain *dominfo, xmlNode *os)
|
|
|
c55d09 |
blist[bl_size] = get_attr_value(child, "dev");
|
|
|
c55d09 |
bl_size++;
|
|
|
c55d09 |
} else if (XSTREQ(child->name, "init"))
|
|
|
c55d09 |
- STRPROP(dominfo, os_info.lxc.init, child);
|
|
|
c55d09 |
+ init = get_node_content(child);
|
|
|
c55d09 |
}
|
|
|
c55d09 |
|
|
|
c55d09 |
if ((STREQC(dominfo->os_info.fv.type, "hvm")) &&
|
|
|
c55d09 |
@@ -1154,17 +1168,39 @@ static int parse_os(struct domain *dominfo, xmlNode *os)
|
|
|
c55d09 |
else
|
|
|
c55d09 |
dominfo->type = -1;
|
|
|
c55d09 |
|
|
|
c55d09 |
- if (STREQC(dominfo->os_info.fv.type, "hvm")) {
|
|
|
c55d09 |
+ switch (dominfo->type) {
|
|
|
c55d09 |
+ case DOMAIN_XENFV:
|
|
|
c55d09 |
+ case DOMAIN_KVM:
|
|
|
c55d09 |
+ case DOMAIN_QEMU:
|
|
|
c55d09 |
+ dominfo->os_info.fv.loader = loader;
|
|
|
c55d09 |
dominfo->os_info.fv.bootlist_ct = bl_size;
|
|
|
c55d09 |
dominfo->os_info.fv.bootlist = blist;
|
|
|
c55d09 |
- } else {
|
|
|
c55d09 |
- int i;
|
|
|
c55d09 |
-
|
|
|
c55d09 |
- for (i = 0; i < bl_size; i++)
|
|
|
c55d09 |
- free(blist[i]);
|
|
|
c55d09 |
- free(blist);
|
|
|
c55d09 |
+ loader = NULL;
|
|
|
c55d09 |
+ blist = NULL;
|
|
|
c55d09 |
+ bl_size = 0;
|
|
|
c55d09 |
+ break;
|
|
|
c55d09 |
+ case DOMAIN_XENPV:
|
|
|
c55d09 |
+ dominfo->os_info.pv.kernel = kernel;
|
|
|
c55d09 |
+ dominfo->os_info.pv.initrd = initrd;
|
|
|
c55d09 |
+ dominfo->os_info.pv.cmdline = cmdline;
|
|
|
c55d09 |
+ kernel = NULL;
|
|
|
c55d09 |
+ initrd = NULL;
|
|
|
c55d09 |
+ cmdline = NULL;
|
|
|
c55d09 |
+ break;
|
|
|
c55d09 |
+ case DOMAIN_LXC:
|
|
|
c55d09 |
+ dominfo->os_info.lxc.init = init;
|
|
|
c55d09 |
+ init = NULL;
|
|
|
c55d09 |
+ break;
|
|
|
c55d09 |
+ default:
|
|
|
c55d09 |
+ break;
|
|
|
c55d09 |
}
|
|
|
c55d09 |
|
|
|
c55d09 |
+ free(kernel);
|
|
|
c55d09 |
+ free(initrd);
|
|
|
c55d09 |
+ free(cmdline);
|
|
|
c55d09 |
+ free(boot);
|
|
|
c55d09 |
+ free(init);
|
|
|
c55d09 |
+ cleanup_bootlist(blist, bl_size);
|
|
|
c55d09 |
return 1;
|
|
|
c55d09 |
}
|
|
|
c55d09 |
|
|
|
c55d09 |
@@ -1360,15 +1396,10 @@ void cleanup_dominfo(struct domain **dominfo)
|
|
|
c55d09 |
free(dom->os_info.pv.cmdline);
|
|
|
c55d09 |
} else if ((dom->type == DOMAIN_XENFV) ||
|
|
|
c55d09 |
(dom->type == DOMAIN_KVM) || (dom->type == DOMAIN_QEMU)) {
|
|
|
c55d09 |
- int i;
|
|
|
c55d09 |
-
|
|
|
c55d09 |
free(dom->os_info.fv.type);
|
|
|
c55d09 |
free(dom->os_info.fv.loader);
|
|
|
c55d09 |
-
|
|
|
c55d09 |
- for (i = 0; i < dom->os_info.fv.bootlist_ct; i++) {
|
|
|
c55d09 |
- free(dom->os_info.fv.bootlist[i]);
|
|
|
c55d09 |
- }
|
|
|
c55d09 |
- free(dom->os_info.fv.bootlist);
|
|
|
c55d09 |
+ cleanup_bootlist(dom->os_info.fv.bootlist,
|
|
|
c55d09 |
+ dom->os_info.fv.bootlist_ct);
|
|
|
c55d09 |
} else if (dom->type == DOMAIN_LXC) {
|
|
|
c55d09 |
free(dom->os_info.lxc.type);
|
|
|
c55d09 |
free(dom->os_info.lxc.init);
|
|
|
c55d09 |
--
|
|
|
c55d09 |
1.8.5.3
|
|
|
c55d09 |
|