[libvirt] [PATCH] phypUUIDTable_Push: do not corrupt output stream

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



This started with clang's report of the two dead stores.
With the increment and decrement by "sent" being performed outside
of the intended loop, the two assignments had no net effect.

BTW, I presume these hard-coded names, from the same function,
are somehow temporary and/or debugging-related:

    char remote_file[] = "/home/hscroot/libvirt_uuid_table";
    char local_file[] = "./uuid_table";


>From a1104c4d1a95b10cab19bacf91ed073769f1d2d7 Mon Sep 17 00:00:00 2001
From: Jim Meyering <meyering@xxxxxxxxxx>
Date: Mon, 1 Mar 2010 21:26:59 +0100
Subject: [PATCH] phypUUIDTable_Push: do not corrupt output stream upon partial write

* src/phyp/phyp_driver.c (phypUUIDTable_Push): Move incr/decr
of ptr/nread into the loop where those variables are used.
Also, remove "exit" label and just-preceding "goto".
---
 src/phyp/phyp_driver.c |    7 ++-----
 1 files changed, 2 insertions(+), 5 deletions(-)

diff --git a/src/phyp/phyp_driver.c b/src/phyp/phyp_driver.c
index 1e8ed30..3fc5a0c 100644
--- a/src/phyp/phyp_driver.c
+++ b/src/phyp/phyp_driver.c
@@ -1982,54 +1982,51 @@ phypUUIDTable_Push(virConnectPtr conn)
     do {
         nread = fread(buffer, 1, sizeof(buffer), fd);
         if (nread <= 0) {
             if (feof(fd)) {
                 /* end of file */
                 break;
             } else {
                 VIR_ERROR("Failed to read from '%s'", local_file);
                 goto err;
             }
         }
         ptr = buffer;
         sent = 0;

         do {
             /* write the same data over and over, until error or completion */
             rc = libssh2_channel_write(channel, ptr, nread);
             if (LIBSSH2_ERROR_EAGAIN == rc) {   /* must loop around */
                 continue;
             } else if (rc > 0) {
                 /* rc indicates how many bytes were written this time */
                 sent += rc;
             }
+            ptr += sent;
+            nread -= sent;
         } while (rc > 0 && sent < nread);
-        ptr += sent;
-        nread -= sent;
     } while (1);

-    goto exit;
-
-  exit:
     if (channel) {
         libssh2_channel_send_eof(channel);
         libssh2_channel_wait_eof(channel);
         libssh2_channel_wait_closed(channel);
         libssh2_channel_free(channel);
         channel = NULL;
     }
     return 0;

   err:
     if (channel) {
         libssh2_channel_send_eof(channel);
         libssh2_channel_wait_eof(channel);
         libssh2_channel_wait_closed(channel);
         libssh2_channel_free(channel);
         channel = NULL;
     }
     return -1;
 }

 int
 phypUUIDTable_Pull(virConnectPtr conn)
 {
--
1.7.0.1.414.g89213d

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list

[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]