nvme: Fix unintentional integer overflow (OVERFLOW_BEFORE_WIDEN)
PATCH 1/1 nvme: Fix unintentional integer overflow (OVERFLOW_BEFORE_WIDEN)
The shift operation on nlb gives a 32 bit result if no type cast is applied. This bug was reported by Coverity.
Signed-off-by Stefan Weil <[email protected]>
--- hw/block/nvme.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
hw/block/nvme.c +1 -1
@@ -222,7 +222,7 @@ static uint16_t nvme_rw(NvmeCtrl *n, NvmeNamespace *ns, NvmeCmd *cmd,uint8_t lba_index =NVME_ID_NS_FLBAS_INDEX (ns->id_ns.flbas);uint8_t data_shift = ns->id_ns.lbaf[lba_index].ds; -uint64_t data_size = nlb << data_shift; +uint64_t data_size = (uint64_t )nlb << data_shift;uint64_t aio_slba = slba << (data_shift -BDRV_SECTOR_BITS );int is_write = rw->opcode ==NVME_CMD_WRITE ?1 :0 ;
Signature · 1 line
1.7.10.4
Stefan Hajnoczi
AppliedQuoted 7 lines · Stefan Weil
The shift operation on nlb gives a 32 bit result if no type cast is applied. This bug was reported by Coverity.
Signed-off-by Stefan Weil <[email protected]>--- hw/block/nvme.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
Thanks, applied to my block tree:
https://github.com/stefanha/qemu/commits/block
Stefan