Skip to content
Permalink
Browse files Browse the repository at this point in the history
dm: validate the input in 'pci_emul_mem_handler()'
 checking the inputs explicitly instead of using Assert.

Tracked-On: #4003
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>
  • Loading branch information
yonghuah authored and wenlingz committed Nov 6, 2019
1 parent 749556e commit 6199e65
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions devicemodel/hw/pci/core.c
Expand Up @@ -416,11 +416,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;

Expand Down

0 comments on commit 6199e65

Please sign in to comment.