Skip to content

Commit

Permalink
PPC: fix out of bound memory access
Browse files Browse the repository at this point in the history
closes #1912
  • Loading branch information
hamarituc committed Sep 7, 2022
1 parent 0d0e684 commit f5e5b5d
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
3 changes: 2 additions & 1 deletion arch/PowerPC/PPCInstPrinter.c
Original file line number Diff line number Diff line change
Expand Up @@ -1150,7 +1150,8 @@ static char *stripRegisterPrefix(const char *RegName)
char *name = cs_strdup(RegName + 2);

// also strip the last 2 letters
name[strlen(name) - 2] = '\0';
if(strlen(name) > 2)
name[strlen(name) - 2] = '\0';

return name;
}
Expand Down
8 changes: 8 additions & 0 deletions suite/cstest/issues.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
!# issue 1912 PPC register name
!# CS_ARCH_PPC, CS_MODE_BIG_ENDIAN, None
0x2d,0x03,0x00,0x80 == cmpwi cr2, r3, 0x80

!# issue 1912 PPC no register name
!# CS_ARCH_PPC, CS_MODE_BIG_ENDIAN, CS_OPT_SYNTAX_NOREGNAME
0x2d,0x03,0x00,0x80 == cmpwi 2, 3, 0x80

!# issue 1902 PPC psq_st negative displacement
!# CS_ARCH_PPC, CS_MODE_32 | CS_MODE_BIG_ENDIAN | CS_MODE_PS, CS_OPT_DETAIL
0xf3,0xec,0x0f,0xf8 == psq_st f31, -8(r12), 0, 0 ; op_count: 4 ; operands[0].type: REG = f31 ; operands[1].type: MEM ; operands[1].mem.base: REG = r12 ; operands[1].mem.disp: 0xfffffff8 ; operands[2].type: IMM = 0x0 ; operands[3].type: IMM = 0x0
Expand Down

0 comments on commit f5e5b5d

Please sign in to comment.