Skip to content

Commit

Permalink
Fix NULL dereference in rz_io_resize() (#4479)
Browse files Browse the repository at this point in the history
  • Loading branch information
pelijah authored May 7, 2024
1 parent 4594027 commit 02990d7
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 20 deletions.
2 changes: 1 addition & 1 deletion librz/include/rz_io.h
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@ RZ_API bool rz_io_write(RzIO *io, const ut8 *buf, size_t len);
RZ_API ut64 rz_io_size(RzIO *io);
RZ_API bool rz_io_is_listener(RzIO *io);
RZ_API char *rz_io_system(RzIO *io, const char *cmd);
RZ_API bool rz_io_resize(RzIO *io, ut64 newsize);
RZ_API bool rz_io_resize(RZ_NONNULL RzIO *io, ut64 newsize);
RZ_API bool rz_io_extend_at(RzIO *io, ut64 addr, ut64 size);
RZ_API bool rz_io_set_write_mask(RzIO *io, const ut8 *mask, size_t len);
RZ_API void rz_io_bind(RzIO *io, RzIOBind *bnd);
Expand Down
36 changes: 17 additions & 19 deletions librz/io/io.c
Original file line number Diff line number Diff line change
Expand Up @@ -422,27 +422,25 @@ RZ_API char *rz_io_system(RzIO *io, const char *cmd) {
return NULL;
}

RZ_API bool rz_io_resize(RzIO *io, ut64 newsize) {
if (io) {
RzList *maps = rz_io_map_get_for_fd(io, io->desc->fd);
RzIOMap *current_map;
RzListIter *iter;
ut64 fd_size = rz_io_fd_size(io, io->desc->fd);
bool ret = rz_io_desc_resize(io->desc, newsize);
if (!ret) {
rz_list_free(maps);
return false;
}
rz_list_foreach (maps, iter, current_map) {
// we just resize map of the same size of its fd
if (current_map->itv.size == fd_size) {
rz_io_map_resize(io, current_map->id, newsize);
}
}
RZ_API bool rz_io_resize(RZ_NONNULL RzIO *io, ut64 newsize) {
rz_return_val_if_fail(io && io->desc, false);

RzList *maps = rz_io_map_get_for_fd(io, io->desc->fd);
ut64 fd_size = rz_io_fd_size(io, io->desc->fd);
if (!rz_io_desc_resize(io->desc, newsize)) {
rz_list_free(maps);
return true;
return false;
}
return false;
RzListIter *iter;
RzIOMap *current_map;
rz_list_foreach (maps, iter, current_map) {
// we just resize map of the same size of its fd
if (current_map->itv.size == fd_size) {
rz_io_map_resize(io, current_map->id, newsize);
}
}
rz_list_free(maps);
return true;
}

RZ_API bool rz_io_close(RzIO *io) {
Expand Down

0 comments on commit 02990d7

Please sign in to comment.