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 regressions in custom memory allocator support #2251

Merged
merged 1 commit into from
Jan 20, 2024
Merged
Show file tree
Hide file tree
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
4 changes: 2 additions & 2 deletions arch/AArch64/AArch64GenAsmWriter.inc
Original file line number Diff line number Diff line change
Expand Up @@ -33293,11 +33293,11 @@ static bool printAliasInstr(MCInst *MI, uint64_t Address, SStream *OS) {
while (AsmString[I] != ' ' && AsmString[I] != '\t' &&
AsmString[I] != '$' && AsmString[I] != '\0')
++I;
char *substr = malloc(I+1);
char *substr = cs_mem_malloc(I+1);
memcpy(substr, AsmString, I);
substr[I] = '\0';
SStream_concat0(OS, substr);
free(substr);
cs_mem_free(substr);
if (AsmString[I] != '\0') {
if (AsmString[I] == ' ' || AsmString[I] == '\t') {
SStream_concat1(OS, ' ');
Expand Down
4 changes: 2 additions & 2 deletions arch/AArch64/AArch64InstPrinter.c
Original file line number Diff line number Diff line change
Expand Up @@ -1312,7 +1312,7 @@ DEFINE_printMatrix(0);
const char *RegName = getRegisterName(MCOperand_getReg(RegOp), AArch64_NoRegAltName); \
\
unsigned buf_len = strlen(RegName) + 1; \
char *Base = calloc(1, buf_len); \
char *Base = cs_mem_calloc(1, buf_len); \
memcpy(Base, RegName, buf_len); \
char *Dot = strchr(Base, '.'); \
if (!Dot) { \
Expand All @@ -1324,7 +1324,7 @@ DEFINE_printMatrix(0);
SStream_concat(O, "%s%s", Base, (IsVertical ? "v" : "h")); \
SStream_concat1(O, '.'); \
SStream_concat0(O, Suffix); \
free(Base); \
cs_mem_free(Base); \
}
DEFINE_printMatrixTileVector(0);
DEFINE_printMatrixTileVector(1);
Expand Down
7 changes: 2 additions & 5 deletions arch/ARM/ARMDisassembler.c
Original file line number Diff line number Diff line change
Expand Up @@ -955,11 +955,8 @@ DecodeStatus AddThumbPredicate(MCInst *MI)
assert(TiedOp >= 0 &&
"Inactive register in vpred_r is not tied to an output!");
// Copy the operand to ensure it's not invalidated when MI grows.
MCOperand *Op = malloc(sizeof(MCOperand));
memcpy(Op, MCInst_getOperand(MI, TiedOp),
sizeof(MCOperand));
MCInst_insert0(MI, VCCPos + 3, Op);
free(Op);
MCOperand Op = *MCInst_getOperand(MI, TiedOp);
MCInst_insert0(MI, VCCPos + 3, &Op);
Copy link
Collaborator

@Rot127 Rot127 Jan 19, 2024

Choose a reason for hiding this comment

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

Not sure about this change. The free() was definitely wrong. But MCInst_insert0() doesn't move Op, but only saves the pointer. So it should be copied on the heap.

Could you take a look at it again.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It makes a copy in the assignment it does here while dereferencing the pointer:

inst->Operands[index] = *Op;

Copy link
Collaborator

Choose a reason for hiding this comment

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

Ah of cause. Missed the line.

}
} else if (VCC != ARMVCC_None) {
Check(&S, MCDisassembler_SoftFail);
Expand Down
4 changes: 2 additions & 2 deletions arch/ARM/ARMGenAsmWriter.inc
Original file line number Diff line number Diff line change
Expand Up @@ -13298,11 +13298,11 @@ static bool printAliasInstr(MCInst *MI, uint64_t Address, SStream *OS)
while (AsmString[I] != ' ' && AsmString[I] != '\t' &&
AsmString[I] != '$' && AsmString[I] != '\0')
++I;
char *substr = malloc(I + 1);
char *substr = cs_mem_malloc(I + 1);
memcpy(substr, AsmString, I);
substr[I] = '\0';
SStream_concat0(OS, substr);
free(substr);
cs_mem_free(substr);
if (AsmString[I] != '\0') {
if (AsmString[I] == ' ' || AsmString[I] == '\t') {
SStream_concat1(OS, ' ');
Expand Down
4 changes: 2 additions & 2 deletions arch/PowerPC/PPCGenAsmWriter.inc
Original file line number Diff line number Diff line change
Expand Up @@ -15689,11 +15689,11 @@ static bool printAliasInstr(MCInst *MI, uint64_t Address, SStream *OS) {
while (AsmString[I] != ' ' && AsmString[I] != '\t' &&
AsmString[I] != '$' && AsmString[I] != '\0')
++I;
char *substr = malloc(I+1);
char *substr = cs_mem_malloc(I+1);
memcpy(substr, AsmString, I);
substr[I] = '\0';
SStream_concat0(OS, substr);
free(substr);
cs_mem_free(substr);
if (AsmString[I] != '\0') {
if (AsmString[I] == ' ' || AsmString[I] == '\t') {
SStream_concat1(OS, ' ');
Expand Down