提交 180ca598 编写于 作者: C Chris Lalancette

Use virGetHostname instead of gethostname.

Fix up qemudDomainMigratePrepare2 to use virGetHostname instead of
gethostname.  Besides the fact that virGetHostname is far more clever,
there was a latent bug in the handling that could cause a buffer overflow
on a very long hostname.
Signed-off-by: NChris Lalancette <clalance@redhat.com>
上级 f24d4671
...@@ -6281,11 +6281,12 @@ qemudDomainMigratePrepare2 (virConnectPtr dconn, ...@@ -6281,11 +6281,12 @@ qemudDomainMigratePrepare2 (virConnectPtr dconn,
virDomainDefPtr def = NULL; virDomainDefPtr def = NULL;
virDomainObjPtr vm = NULL; virDomainObjPtr vm = NULL;
int this_port; int this_port;
char hostname [HOST_NAME_MAX+1]; char *hostname;
char migrateFrom [64]; char migrateFrom [64];
const char *p; const char *p;
virDomainEventPtr event = NULL; virDomainEventPtr event = NULL;
int ret = -1;; int ret = -1;;
int internalret;
*uri_out = NULL; *uri_out = NULL;
...@@ -6311,14 +6312,16 @@ qemudDomainMigratePrepare2 (virConnectPtr dconn, ...@@ -6311,14 +6312,16 @@ qemudDomainMigratePrepare2 (virConnectPtr dconn,
if (port == QEMUD_MIGRATION_NUM_PORTS) port = 0; if (port == QEMUD_MIGRATION_NUM_PORTS) port = 0;
/* Get hostname */ /* Get hostname */
if (gethostname (hostname, HOST_NAME_MAX+1) == -1) { if ((hostname = virGetHostname()) == NULL) {
virReportSystemError (dconn, errno, virReportSystemError (dconn, errno,
"%s", _("failed to determine host name")); "%s", _("failed to determine host name"));
goto cleanup; goto cleanup;
} }
/* Caller frees */ /* Caller frees */
if (virAsprintf(uri_out, "tcp:%s:%d", hostname, this_port) < 0) { internalret = virAsprintf(uri_out, "tcp:%s:%d", hostname, this_port);
VIR_FREE(hostname);
if (internalret < 0) {
virReportOOMError (dconn); virReportOOMError (dconn);
goto cleanup; goto cleanup;
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册