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

[PPC] Fix random branch hint and update_cr0 set up. #2028

Merged
merged 1 commit into from
May 22, 2023

Conversation

Rot127
Copy link
Collaborator

@Rot127 Rot127 commented May 21, 2023

The branch hint and the update_cr0 flag can be set to true at random.

Those flags are set here:

void PPC_post_printer(csh ud, cs_insn *insn, char *insn_asm, MCInst *mci)
{
if (((cs_struct *)ud)->detail != CS_OPT_ON)
return;
// check if this insn has branch hint
if (strrchr(insn->mnemonic, '+') != NULL && !strstr(insn_asm, ".+")) {
insn->detail->ppc.bh = PPC_BH_PLUS;
} else if (strrchr(insn->mnemonic, '-') != NULL) {
insn->detail->ppc.bh = PPC_BH_MINUS;
}
if (strrchr(insn->mnemonic, '.') != NULL) {
insn->detail->ppc.update_cr0 = true;
}
}

Because the cs_insn->mnemonic gets filled after the PPC_post_printer() is called and cs_insn->mnemonic is not memset to 0 before, PPC_post_printer() tests cs_insn->mnemonic with random data.

This in turn leads randomly to incorrect setting of the branch hints and the update_cr0 flag.

The branch hints and update_cr0 flag will no longer set by checking the mnemonic once the auto-sync update is done. So this is really just a hotfix until #2013 is merged.

Because the cs_insn->mnemonic gets set *after* the
post_printer is called and cs_insn->mnemonic is not memset to 0
before, post_printer() of PPC receives a cs_insn->mnemonic with
random data.
This in turn leads randomly to incorrect setting of the branch hints
and the update_cr0 flag. Because those are set in the post_printer()
of PPC.
@Rot127 Rot127 changed the title Set mnemonic in PPC_printInst() [PPC] Set mnemonic in PPC_printInst() May 21, 2023
@Rot127 Rot127 changed the title [PPC] Set mnemonic in PPC_printInst() [PPC] Fix random branch hint and update_cr0 set up. May 21, 2023
@Rot127 Rot127 mentioned this pull request May 21, 2023
5 tasks
@kabeor kabeor merged commit 80ede42 into capstone-engine:next May 22, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants