]> xenbits.xensource.com Git - qemu-xen.git/commitdiff
ipmi: check return of qemu_chr_fe_write() for errors
authorDaniel P. Berrange <berrange@redhat.com>
Tue, 6 Sep 2016 13:56:02 +0000 (14:56 +0100)
committerPaolo Bonzini <pbonzini@redhat.com>
Tue, 13 Sep 2016 17:09:42 +0000 (19:09 +0200)
The continue_send() method in ipmi_bmc_extern.c directly
assigns the return value of qemu_chr_fe_write() to the
variable tracking the I/O buffer offset. This ignores the
possibility that the return value could be -1 and so will
cause I/O go backwards on EAGAIN. Fortunately 'outpos' is
unsigned, so can't go negative - it will become MAX_INT
which will cause the loop to stop, and avoid an accidental
out of bounds array access.

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
Message-Id: <1473170165-540-2-git-send-email-berrange@redhat.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
hw/ipmi/ipmi_bmc_extern.c

index 5b73983e7d4ff447013d920190ed9a7f326b60cb..d93e3f3426519f2d132714b6819ec75ab9ffc7ae 100644 (file)
@@ -100,12 +100,16 @@ ipmb_checksum(const unsigned char *data, int size, unsigned char start)
 
 static void continue_send(IPMIBmcExtern *ibe)
 {
+    int ret;
     if (ibe->outlen == 0) {
         goto check_reset;
     }
  send:
-    ibe->outpos += qemu_chr_fe_write(ibe->chr, ibe->outbuf + ibe->outpos,
-                                     ibe->outlen - ibe->outpos);
+    ret = qemu_chr_fe_write(ibe->chr, ibe->outbuf + ibe->outpos,
+                            ibe->outlen - ibe->outpos);
+    if (ret > 0) {
+        ibe->outpos += ret;
+    }
     if (ibe->outpos < ibe->outlen) {
         /* Not fully transmitted, try again in a 10ms */
         timer_mod_ns(ibe->extern_timer,