Fix heap corruption in Rust bindings (#62)

RabbitizerInstruction_getSizeForBuffer and
RabbitizerOperandType_getBufferSize return
the size _without_ the null terminator, so
we need to allocate one more byte to avoid
writing past the allocated vector bounds.
This commit is contained in:
Luke Street 2024-05-22 10:33:15 -06:00 committed by GitHub
parent f5c65d02d1
commit 4dd2a55588
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 2 additions and 2 deletions

View File

@ -709,7 +709,7 @@ impl Instruction {
let buffer_size =
RabbitizerInstruction_getSizeForBuffer(self, imm_override_len, extra_l_just);
let mut buffer: Vec<u8> = vec![0; buffer_size];
let mut buffer: Vec<u8> = vec![0; buffer_size + 1];
let disassembled_size = RabbitizerInstruction_disassemble(
self,
buffer.as_mut_ptr() as *mut core::ffi::c_char,

View File

@ -30,7 +30,7 @@ impl operand_type_enum::OperandType {
unsafe {
let buffer_size = RabbitizerOperandType_getBufferSize(*self, instr, imm_override_len);
let mut buffer: Vec<u8> = vec![0; buffer_size];
let mut buffer: Vec<u8> = vec![0; buffer_size + 1];
let disassembled_size = RabbitizerOperandType_disassemble(
*self,
instr,