From 76f0ae32615dc1fbe120636626f691b6d20ece31 Mon Sep 17 00:00:00 2001 From: Matthias Bolte Date: Sun, 3 Apr 2011 11:21:25 +0200 Subject: [PATCH] daemon: Remove 4kb stack allocation of security label --- daemon/remote.c | 32 ++++++++++++++++++++------------ 1 file changed, 20 insertions(+), 12 deletions(-) diff --git a/daemon/remote.c b/daemon/remote.c index 1700c2d37b..dd85ef16da 100644 --- a/daemon/remote.c +++ b/daemon/remote.c @@ -1607,7 +1607,7 @@ remoteDispatchDomainGetSecurityLabel(struct qemud_server *server ATTRIBUTE_UNUSE remote_domain_get_security_label_ret *ret) { virDomainPtr dom; - virSecurityLabel seclabel; + virSecurityLabelPtr seclabel; dom = get_nonnull_domain(conn, args->dom); if (dom == NULL) { @@ -1615,22 +1615,30 @@ remoteDispatchDomainGetSecurityLabel(struct qemud_server *server ATTRIBUTE_UNUSE return -1; } - memset(&seclabel, 0, sizeof seclabel); - if (virDomainGetSecurityLabel(dom, &seclabel) == -1) { - remoteDispatchConnError(rerr, conn); - virDomainFree(dom); - return -1; - } - - ret->label.label_len = strlen(seclabel.label) + 1; - if (VIR_ALLOC_N(ret->label.label_val, ret->label.label_len) < 0) { + if (VIR_ALLOC(seclabel) < 0) { virDomainFree(dom); remoteDispatchOOMError(rerr); return -1; } - strcpy(ret->label.label_val, seclabel.label); - ret->enforcing = seclabel.enforcing; + + if (virDomainGetSecurityLabel(dom, seclabel) == -1) { + remoteDispatchConnError(rerr, conn); + virDomainFree(dom); + VIR_FREE(seclabel); + return -1; + } + + ret->label.label_len = strlen(seclabel->label) + 1; + if (VIR_ALLOC_N(ret->label.label_val, ret->label.label_len) < 0) { + virDomainFree(dom); + VIR_FREE(seclabel); + remoteDispatchOOMError(rerr); + return -1; + } + strcpy(ret->label.label_val, seclabel->label); + ret->enforcing = seclabel->enforcing; virDomainFree(dom); + VIR_FREE(seclabel); return 0; }