dm: validate the input in 'pci_emul_mem_handler()'

checking the inputs explicitly instead of using Assert.

Tracked-On: #3991
Signed-off-by: Yonghua Huang <yonghua.huang@intel.com>
Reviewed-by: Shuo Liu <shuo.a.liu@intel.com>
Acked-by: Yu Wang <yu1.wang@intel.com>
This commit is contained in:
Yonghua Huang 2019-11-04 09:09:35 +08:00 committed by wenlingz
parent 21af6c84a4
commit cf6ba23fd9

View File

@ -417,11 +417,10 @@ pci_emul_mem_handler(struct vmctx *ctx, int vcpu, int dir, uint64_t addr,
uint64_t offset; uint64_t offset;
int bidx = (int) arg2; int bidx = (int) arg2;
assert(bidx <= PCI_BARMAX); if (addr + size > pdi->bar[bidx].addr + pdi->bar[bidx].size) {
assert(pdi->bar[bidx].type == PCIBAR_MEM32 || printf("%s, Out of emulated memory range.\n", __func__);
pdi->bar[bidx].type == PCIBAR_MEM64); return -ESRCH;
assert(addr >= pdi->bar[bidx].addr && }
addr + size <= pdi->bar[bidx].addr + pdi->bar[bidx].size);
offset = addr - pdi->bar[bidx].addr; offset = addr - pdi->bar[bidx].addr;