Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix OOB in the Gameboy instruction decoder ##anal #17088

Merged
merged 1 commit into from
Jul 2, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions libr/anal/p/anal_gb.c
Original file line number Diff line number Diff line change
Expand Up @@ -714,8 +714,11 @@ static bool gb_custom_daa (RAnalEsil *esil) {
static int gb_anop(RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *data, int len, RAnalOpMask mask) {
int ilen = gbOpLength (gb_op[data[0]].type);
if (ilen > len) {
ilen = 0;
} else if (mask & R_ANAL_OP_MASK_DISASM) {
op->type = R_ANAL_OP_TYPE_ILL;
op->size = 0;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you may set op->size = ilen; this way the caller knows the size of the instruction that was not possible to disassebmle because of lack of data provided

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

well, I can do that, but that requires the caller to check the return value and the value in op. ... Maybe one should consider making plugin->op return a bool instead of length?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah seems like an option here. Enforcing opsize only in one place and return bool to specify success or not. The reason can be found in the ranalop struct if needed. But that should be done in another pr. Kinda big change i guess

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, so for now, I'd like to keep this as it is

return 0;
}
if (mask & R_ANAL_OP_MASK_DISASM) {
char mn[32];
memset (mn, '\0', sizeof (char) * sizeof (mn));
char reg[32];
Expand Down