Move sanity checks before uc->memory_map is called.

This commit is contained in:
farmdve 2016-01-11 18:26:23 +02:00
parent c9f4bd27cc
commit 89eac66bf7

40
uc.c
View file

@ -606,26 +606,6 @@ static uc_err mem_map(uc_engine *uc, uint64_t address, size_t size, uint32_t per
{ {
MemoryRegion **regions; MemoryRegion **regions;
if (size == 0)
// invalid memory mapping
return UC_ERR_ARG;
// address cannot wrapp around
if (address + size - 1 < address)
return UC_ERR_ARG;
// address must be aligned to uc->target_page_size
if ((address & uc->target_page_align) != 0)
return UC_ERR_ARG;
// size must be multiple of uc->target_page_size
if ((size & uc->target_page_align) != 0)
return UC_ERR_ARG;
// check for only valid permissions
if ((perms & ~UC_PROT_ALL) != 0)
return UC_ERR_ARG;
// this area overlaps existing mapped regions? // this area overlaps existing mapped regions?
if (memory_overlap(uc, address, size)) if (memory_overlap(uc, address, size))
return UC_ERR_MAP; return UC_ERR_MAP;
@ -655,6 +635,26 @@ uc_err uc_mem_map(uc_engine *uc, uint64_t address, size_t size, uint32_t perms)
address = uc->mem_redirect(address); address = uc->mem_redirect(address);
} }
if (size == 0)
// invalid memory mapping
return UC_ERR_ARG;
// address cannot wrapp around
if (address + size - 1 < address)
return UC_ERR_ARG;
// address must be aligned to uc->target_page_size
if ((address & uc->target_page_align) != 0)
return UC_ERR_ARG;
// size must be multiple of uc->target_page_size
if ((size & uc->target_page_align) != 0)
return UC_ERR_ARG;
// check for only valid permissions
if ((perms & ~UC_PROT_ALL) != 0)
return UC_ERR_ARG;
return mem_map(uc, address, size, perms, uc->memory_map(uc, address, size, perms)); return mem_map(uc, address, size, perms, uc->memory_map(uc, address, size, perms));
} }