Add some more checks for null derefs related to io bank relocs

This commit is contained in:
pancake 2022-12-29 17:12:17 +01:00
parent 842f809d4e
commit db405b93e3
2 changed files with 3 additions and 3 deletions

View File

@ -832,7 +832,7 @@ R_API bool r_io_bank_write_at(RIO *io, const ut32 bankid, ut64 addr, const ut8 *
const ut64 buf_off = R_MAX (addr, r_io_submap_from (sm)) - addr;
const int write_len = R_MIN (r_io_submap_to ((&fake_sm)),
r_io_submap_to (sm)) - (addr + buf_off) + 1;
if (map->perm & R_PERM_RELOC) {
if (map->perm & R_PERM_RELOC && map->reloc_map) {
ret &= map->reloc_map->write (io, map, addr + buf_off, &buf[buf_off], write_len);
} else {
const ut64 paddr = addr + buf_off - r_io_map_from (map) + map->delta;
@ -912,7 +912,7 @@ R_API int r_io_bank_write_to_submap_at(RIO *io, const ut32 bankid, ut64 addr, co
return -1;
}
const int write_len = R_MIN (len, r_io_submap_to (sm) - addr + 1);
if (map->perm & R_PERM_RELOC) {
if (map->perm & R_PERM_RELOC && map->reloc_map) {
return map->reloc_map->write (io, map, addr, buf, write_len);
}
const ut64 paddr = addr - r_io_map_from (map) + map->delta;

View File

@ -35,7 +35,7 @@ R_API bool r_io_map_remap(RIO *io, ut32 id, ut64 addr) {
const ut64 ofrom = r_io_map_from (map);
const ut64 oto = r_io_map_to (map);
ut64 size = r_io_map_size (map);
if (map->perm & R_PERM_RELOC) {
if (map->perm & R_PERM_RELOC && map->reloc_map) {
if (R_UNLIKELY (UT64_MAX - size + 1 < addr)) {
R_LOG_ERROR ("Mapsplit for reloc maps is not possible");
return false;