]> git.proxmox.com Git - mirror_qemu.git/commitdiff
megasas: do not read sense length more than once from frame
authorPaolo Bonzini <pbonzini@redhat.com>
Thu, 1 Jun 2017 15:18:39 +0000 (17:18 +0200)
committerMichael Roth <mdroth@linux.vnet.ibm.com>
Thu, 31 Aug 2017 16:51:16 +0000 (11:51 -0500)
Avoid TOC-TOU bugs depending on how the compiler behaves.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
(cherry picked from commit 134550bf81a026e18cf58b81e2c2cceaf516f92e)
Signed-off-by: Michael Roth <mdroth@linux.vnet.ibm.com>
hw/scsi/megasas.c

index 804122ab0519332d0654a9a2572be2431bacddcf..1888118e5f29f45734f088a71b75632a94263842 100644 (file)
@@ -309,9 +309,11 @@ static int megasas_build_sense(MegasasCmd *cmd, uint8_t *sense_ptr,
     PCIDevice *pcid = PCI_DEVICE(cmd->state);
     uint32_t pa_hi = 0, pa_lo;
     hwaddr pa;
+    int frame_sense_len;
 
-    if (sense_len > cmd->frame->header.sense_len) {
-        sense_len = cmd->frame->header.sense_len;
+    frame_sense_len = cmd->frame->header.sense_len;
+    if (sense_len > frame_sense_len) {
+        sense_len = frame_sense_len;
     }
     if (sense_len) {
         pa_lo = le32_to_cpu(cmd->frame->pass.sense_addr_lo);