]> xenbits.xensource.com Git - people/liuw/libxenctrl-split/libvirt.git/commitdiff
uml: avoid crash on partial read
authorEric Blake <eblake@redhat.com>
Wed, 3 Mar 2010 00:16:05 +0000 (17:16 -0700)
committerJim Meyering <meyering@redhat.com>
Wed, 3 Mar 2010 09:17:31 +0000 (10:17 +0100)
Coverity detected a potential dereference of uninitialized memory
if recvfrom got cut short.

* src/uml/uml_driver.c (umlMonitorCommand): Validate complete read
prior to dereferencing res.

src/uml/uml_driver.c

index bbea4295f38bd388eaeee181684e21b1dab791e9..eec239f4ffab85efc921283b72485eee2998f8c1 100644 (file)
@@ -733,14 +733,24 @@ static int umlMonitorCommand(virConnectPtr conn,
     }
 
     do {
+        ssize_t nbytes;
         addrlen = sizeof(addr);
-        if (recvfrom(priv->monitor, &res, sizeof res, 0,
-                     (struct sockaddr *)&addr, &addrlen) < 0) {
+        nbytes = recvfrom(priv->monitor, &res, sizeof res, 0,
+                          (struct sockaddr *)&addr, &addrlen) < 0;
+        if (nbytes < 0) {
+            if (errno == EAGAIN || errno == EINTR)
+                continue;
             virReportSystemError(errno,
                                  _("cannot read reply %s"),
                                  cmd);
             goto error;
         }
+        if (nbytes < sizeof res) {
+            virReportSystemError(errno,
+                                 _("incomplete reply %s"),
+                                 cmd);
+            goto error;
+        }
 
         if (VIR_REALLOC_N(retdata, retlen + res.length) < 0) {
             virReportOOMError();