提交 37ce5600 编写于 作者: J Jim Meyering

xenDaemonDomainSetAutostart: avoid appearance of impropriety

* src/xen/xend_internal.c (xenDaemonDomainSetAutostart): Rewrite to
avoid dereferencing the result of sexpr_lookup.  While in this
particular case, it was guaranteed never to be NULL, due to the
preceding "if sexpr_node(...)" guard, it's cleaner to skip the
sexpr_node call altogether, and also saves a lookup.
上级 e52687e8
...@@ -4383,7 +4383,6 @@ xenDaemonDomainSetAutostart(virDomainPtr domain, ...@@ -4383,7 +4383,6 @@ xenDaemonDomainSetAutostart(virDomainPtr domain,
int autostart) int autostart)
{ {
struct sexpr *root, *autonode; struct sexpr *root, *autonode;
const char *autostr;
char buf[4096]; char buf[4096];
int ret = -1; int ret = -1;
xenUnifiedPrivatePtr priv; xenUnifiedPrivatePtr priv;
...@@ -4408,16 +4407,17 @@ xenDaemonDomainSetAutostart(virDomainPtr domain, ...@@ -4408,16 +4407,17 @@ xenDaemonDomainSetAutostart(virDomainPtr domain,
return (-1); return (-1);
} }
autostr = sexpr_node(root, "domain/on_xend_start"); autonode = sexpr_lookup(root, "domain/on_xend_start");
if (autostr) { if (autonode) {
if (!STREQ(autostr, "ignore") && !STREQ(autostr, "start")) { const char *val = (autonode->u.s.car->kind == SEXPR_VALUE
? autonode->u.s.car->u.value : NULL);
if (!STREQ(val, "ignore") && !STREQ(val, "start")) {
virXendError(domain->conn, VIR_ERR_INTERNAL_ERROR, virXendError(domain->conn, VIR_ERR_INTERNAL_ERROR,
"%s", _("unexpected value from on_xend_start")); "%s", _("unexpected value from on_xend_start"));
goto error; goto error;
} }
// Change the autostart value in place, then define the new sexpr // Change the autostart value in place, then define the new sexpr
autonode = sexpr_lookup(root, "domain/on_xend_start");
VIR_FREE(autonode->u.s.car->u.value); VIR_FREE(autonode->u.s.car->u.value);
autonode->u.s.car->u.value = (autostart ? strdup("start") autonode->u.s.car->u.value = (autostart ? strdup("start")
: strdup("ignore")); : strdup("ignore"));
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册