diff --git a/src/xen/xen_driver.c b/src/xen/xen_driver.c index 6cb4f4fc31800e316671dd55946c660ec0c7ccd9..40b98ee59161f37edcb2f84ff4a830cf9aeb802a 100644 --- a/src/xen/xen_driver.c +++ b/src/xen/xen_driver.c @@ -1604,7 +1604,8 @@ xenUnifiedConnectDomainXMLFromNative(virConnectPtr conn, def = xenParseXM(conf, priv->xendConfigVersion, priv->caps); } else if (STREQ(format, XEN_CONFIG_FORMAT_SEXPR)) { - id = xenGetDomIdFromSxprString(config, priv->xendConfigVersion); + if (xenGetDomIdFromSxprString(config, priv->xendConfigVersion, &id) < 0) + goto cleanup; xenUnifiedLock(priv); tty = xenStoreDomainGetConsolePath(conn, id); vncport = xenStoreDomainGetVNCPort(conn, id); diff --git a/src/xen/xend_internal.c b/src/xen/xend_internal.c index f698c8de78468f5bf3c2955bd2bd725449feb7f8..dc57350e2507440bc7ea1514a09347e74aa2a058 100644 --- a/src/xen/xend_internal.c +++ b/src/xen/xend_internal.c @@ -1561,7 +1561,7 @@ xenDaemonDomainFetch(virConnectPtr conn, int domid, const char *name, { struct sexpr *root; xenUnifiedPrivatePtr priv = conn->privateData; - virDomainDefPtr def; + virDomainDefPtr def = NULL; int id; char * tty; int vncport; @@ -1573,7 +1573,8 @@ xenDaemonDomainFetch(virConnectPtr conn, int domid, const char *name, if (root == NULL) return NULL; - id = xenGetDomIdFromSxpr(root, priv->xendConfigVersion); + if (xenGetDomIdFromSxpr(root, priv->xendConfigVersion, &id) < 0) + goto cleanup; xenUnifiedLock(priv); if (sexpr_lookup(root, "domain/image/hvm")) tty = xenStoreDomainGetSerialConsolePath(conn, id); @@ -3224,7 +3225,7 @@ xenDaemonDomainBlockPeek(virConnectPtr conn, xenUnifiedPrivatePtr priv = conn->privateData; struct sexpr *root = NULL; int fd = -1, ret = -1; - virDomainDefPtr def; + virDomainDefPtr def = NULL; int id; char * tty; int vncport; @@ -3249,7 +3250,8 @@ xenDaemonDomainBlockPeek(virConnectPtr conn, return -1; } - id = xenGetDomIdFromSxpr(root, priv->xendConfigVersion); + if (xenGetDomIdFromSxpr(root, priv->xendConfigVersion, &id) < 0) + goto cleanup; xenUnifiedLock(priv); tty = xenStoreDomainGetConsolePath(conn, id); vncport = xenStoreDomainGetVNCPort(conn, id); diff --git a/src/xenxs/xen_sxpr.c b/src/xenxs/xen_sxpr.c index 462eac6a99e9aaba7a990a72981a129eaa8d95ca..bb8a335cf53dd30b51f3ddf9985643d49441f8b9 100644 --- a/src/xenxs/xen_sxpr.c +++ b/src/xenxs/xen_sxpr.c @@ -40,30 +40,33 @@ #include "virstring.h" /* Get a domain id from a S-expression string */ -int xenGetDomIdFromSxprString(const char *sexpr, int xendConfigVersion) +int xenGetDomIdFromSxprString(const char *sexpr, int xendConfigVersion, int *id) { struct sexpr *root = string2sexpr(sexpr); + int ret; + + *id = -1; if (!root) return -1; - int id = xenGetDomIdFromSxpr(root, xendConfigVersion); + ret = xenGetDomIdFromSxpr(root, xendConfigVersion, id); sexpr_free(root); - return id; + return ret; } /* Get a domain id from a S-expression */ -int xenGetDomIdFromSxpr(const struct sexpr *root, int xendConfigVersion) +int xenGetDomIdFromSxpr(const struct sexpr *root, int xendConfigVersion, int *id) { - int id = -1; const char * tmp = sexpr_node(root, "domain/domid"); if (tmp == NULL && xendConfigVersion < XEND_CONFIG_VERSION_3_0_4) { /* domid was mandatory */ virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("domain information incomplete, missing id")); + return -1; } else { - id = tmp ? sexpr_int(root, "domain/domid") : -1; + *id = tmp ? sexpr_int(root, "domain/domid") : -1; + return 0; } - return id; } /***************************************************************** diff --git a/src/xenxs/xen_sxpr.h b/src/xenxs/xen_sxpr.h index d7ce46a3dd8a0f1602f7c9d699ee6be08679bbcd..f354a50db727293f342a8606941e5a4f56b7498b 100644 --- a/src/xenxs/xen_sxpr.h +++ b/src/xenxs/xen_sxpr.h @@ -40,8 +40,8 @@ typedef enum { } xenConfigVersionEnum; /* helper functions to get the dom id from a sexpr */ -int xenGetDomIdFromSxprString(const char *sexpr, int xendConfigVersion); -int xenGetDomIdFromSxpr(const struct sexpr *root, int xendConfigVersion); +int xenGetDomIdFromSxprString(const char *sexpr, int xendConfigVersion, int *id); +int xenGetDomIdFromSxpr(const struct sexpr *root, int xendConfigVersion, int *id); virDomainDefPtr xenParseSxprString(const char *sexpr, int xendConfigVersion, char *tty, int vncport); diff --git a/tests/sexpr2xmltest.c b/tests/sexpr2xmltest.c index eafefda0c72646c9af5f94f2d24da9fd24617a2e..b939319a8ebde4b1bd7435fcd299065ba05b030e 100644 --- a/tests/sexpr2xmltest.c +++ b/tests/sexpr2xmltest.c @@ -50,7 +50,8 @@ testCompareFiles(const char *xml, const char *sexpr, int xendConfigVersion) if (virMutexInit(&priv.lock) < 0) goto fail; - id = xenGetDomIdFromSxprString(sexprData, xendConfigVersion); + if (xenGetDomIdFromSxprString(sexprData, xendConfigVersion, &id) < 0) + goto fail; xenUnifiedLock(&priv); tty = xenStoreDomainGetConsolePath(conn, id); vncport = xenStoreDomainGetVNCPort(conn, id);