diff --git a/uc.c b/uc.c index 7e2d5fa1..2c8f9f1d 100644 --- a/uc.c +++ b/uc.c @@ -588,6 +588,10 @@ uc_err uc_mem_map(uc_engine *uc, uint64_t address, size_t size, uint32_t perms) // 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; @@ -845,7 +849,7 @@ MemoryRegion *memory_mapping(struct uc_struct* uc, uint64_t address) return uc->mapped_blocks[i]; for(i = 0; i < uc->mapped_block_count; i++) { - if (address >= uc->mapped_blocks[i]->addr && address < uc->mapped_blocks[i]->end) { + if (address >= uc->mapped_blocks[i]->addr && address <= uc->mapped_blocks[i]->end - 1) { // cache this index for the next query uc->mapped_block_cache_index = i; return uc->mapped_blocks[i];