Skip to content

Commit

Permalink
pyc: fix fpe and heap buffer overflow (#3922)
Browse files Browse the repository at this point in the history
* Fix div by zero in le_create_maps()

* Fix heap buffer overflow in marshal.c

* Make error messages like in cpython

* Refactor le_create_maps()

* Refactor marshal.c
  • Loading branch information
ttxine authored Oct 16, 2023
1 parent 51c8be0 commit bfef566
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 9 deletions.
3 changes: 2 additions & 1 deletion librz/bin/format/le/le.c
Original file line number Diff line number Diff line change
Expand Up @@ -1128,7 +1128,8 @@ static RzVector /*<LE_map>*/ *le_create_maps(rz_bin_le_obj_t *bin) {
rz_vector_foreach(le_maps, m) {
max_vaddr = RZ_MAX(max_vaddr, m->vaddr + m->vsize);
}
bin->reloc_target_map_base = max_vaddr - max_vaddr % h->pagesize + h->pagesize * 2;
CHECK(h->pagesize);
bin->reloc_target_map_base = max_vaddr - (max_vaddr % h->pagesize) + (h->pagesize * 2);

return le_maps;
}
Expand Down
18 changes: 10 additions & 8 deletions librz/bin/format/pyc/marshal.c
Original file line number Diff line number Diff line change
Expand Up @@ -679,21 +679,23 @@ static pyc_object *get_ascii_object_generic(RzBinPycObj *pyc, RzBuffer *buffer,

static pyc_object *get_ascii_object(RzBinPycObj *pyc, RzBuffer *buffer) {
bool error = false;
ut32 n = 0;

n = get_ut32(buffer, &error);
if (error) {
ut32 n = get_ut32(buffer, &error);
if (n > ST32_MAX) {
RZ_LOG_ERROR("bad marshal data (string size out of range)\n");
return NULL;
} else if (error) {
return NULL;
}
return get_ascii_object_generic(pyc, buffer, n, true);
}

static pyc_object *get_ascii_interned_object(RzBinPycObj *pyc, RzBuffer *buffer) {
bool error = false;
ut32 n;

n = get_ut32(buffer, &error);
if (error) {
ut32 n = get_ut32(buffer, &error);
if (n > ST32_MAX) {
RZ_LOG_ERROR("bad marshal data (string size out of range)\n");
return NULL;
} else if (error) {
return NULL;
}
return get_ascii_object_generic(pyc, buffer, n, true);
Expand Down

0 comments on commit bfef566

Please sign in to comment.