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 some UBSan errors #339

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
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
49 changes: 31 additions & 18 deletions src/dec/xed-ild.c
Original file line number Diff line number Diff line change
Expand Up @@ -917,23 +917,27 @@ static void disp_scanner(xed_decoded_inst_t* d)

switch(ilog2[disp_bytes]) {
case 0: { // 1B=8b. ilog2(1) = 0
xed_int8_t byte = *(xed_int8_t*)disp_ptr;
xed3_operand_set_disp(d, byte);
xed_int8_t disp = 0;
memcpy(&disp, disp_ptr, sizeof(disp));
xed3_operand_set_disp(d, disp);
break;
}
case 1: { // 2B=16b ilog2(2) = 1
xed_int16_t word = *(xed_int16_t*)disp_ptr;
xed3_operand_set_disp(d, word);
xed_int16_t disp = 0;
memcpy(&disp, disp_ptr, sizeof(disp));
xed3_operand_set_disp(d, disp);
break;
}
case 2: { // 4B=32b ilog2(4) = 2
xed_int32_t dword = *(xed_int32_t*)disp_ptr;
xed3_operand_set_disp(d, dword);
xed_int32_t disp = 0;
memcpy(&disp, disp_ptr, sizeof(disp));
xed3_operand_set_disp(d, disp);
break;
}
case 3: {// 8B=64b ilog2(8) = 3
xed_int64_t qword = *(xed_int64_t*)disp_ptr;
xed3_operand_set_disp(d, qword);
xed_int64_t disp = 0;
memcpy(&disp, disp_ptr, sizeof(disp));
xed3_operand_set_disp(d, disp);
break;
}
default:
Expand Down Expand Up @@ -1555,23 +1559,32 @@ static void imm_scanner(xed_decoded_inst_t* d)
switch(imm_bytes) {
case 0:
break;
case 1: {
xed_uint8_t uimm0 = *imm_ptr;
case 1: {
xed_uint8_t uimm0 = 0;
memcpy(&uimm0, imm_ptr, sizeof(uimm0));
xed_uint8_t esrc = uimm0 >> 4;

xed3_operand_set_uimm0(d, uimm0);
xed3_operand_set_esrc(d, esrc);
break;
}
case 2:
xed3_operand_set_uimm0(d, *(xed_uint16_t*)imm_ptr);
}
case 2: {
xed_uint16_t uimm0 = 0;
memcpy(&uimm0, imm_ptr, sizeof(uimm0));
xed3_operand_set_uimm0(d, uimm0);
break;
case 4:
xed3_operand_set_uimm0(d, *(xed_uint32_t*)imm_ptr);
}
case 4: {
xed_uint32_t uimm0 = 0;
memcpy(&uimm0, imm_ptr, sizeof(uimm0));
xed3_operand_set_uimm0(d, uimm0);
break;
case 8:
xed3_operand_set_uimm0(d, *(xed_uint64_t*)imm_ptr);
}
case 8: {
xed_uint64_t uimm0 = 0;
memcpy(&uimm0, imm_ptr, sizeof(uimm0));
xed3_operand_set_uimm0(d, uimm0);
break;
}
default:
/*Unexpected immediate width, this should never happen*/
xed_assert(0);
Expand Down