]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
Use virGetHostname instead of gethostname.
authorChris Lalancette <clalance@redhat.com>
Thu, 30 Jul 2009 14:41:12 +0000 (16:41 +0200)
committerChris Lalancette <clalance@redhat.com>
Sun, 2 Aug 2009 10:07:02 +0000 (12:07 +0200)
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: Chris Lalancette <clalance@redhat.com>
src/qemu_driver.c

index e7a6b9b8e14b80b3afabf25b1aba56fae946647b..aaef763b0be6e877059ca9c3ae41d9729c14db44 100644 (file)
@@ -6281,11 +6281,12 @@ qemudDomainMigratePrepare2 (virConnectPtr dconn,
     virDomainDefPtr def = NULL;
     virDomainObjPtr vm = NULL;
     int this_port;
-    char hostname [HOST_NAME_MAX+1];
+    char *hostname;
     char migrateFrom [64];
     const char *p;
     virDomainEventPtr event = NULL;
     int ret = -1;;
+    int internalret;
 
     *uri_out = NULL;
 
@@ -6311,14 +6312,16 @@ qemudDomainMigratePrepare2 (virConnectPtr dconn,
         if (port == QEMUD_MIGRATION_NUM_PORTS) port = 0;
 
         /* Get hostname */
-        if (gethostname (hostname, HOST_NAME_MAX+1) == -1) {
+        if ((hostname = virGetHostname()) == NULL) {
             virReportSystemError (dconn, errno,
                                   "%s", _("failed to determine host name"));
             goto cleanup;
         }
 
         /* 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);
             goto cleanup;
         }