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;
int bidx = (int) arg2;
assert(bidx <= PCI_BARMAX);
assert(pdi->bar[bidx].type == PCIBAR_MEM32 ||
pdi->bar[bidx].type == PCIBAR_MEM64);
assert(addr >= pdi->bar[bidx].addr &&
addr + size <= pdi->bar[bidx].addr + pdi->bar[bidx].size);
if (addr + size > pdi->bar[bidx].addr + pdi->bar[bidx].size) {
printf("%s, Out of emulated memory range.\n", __func__);
return -ESRCH;
}
offset = addr - pdi->bar[bidx].addr;