Skip to content

Commit e75d518

Browse files
committed
fix AflppRedQueen mutator's u64 I2S replacement
When the RQ mutator sees that a 8 byte comparison operand is equal to 8 bytes from the input, then it treats that as an I2S correspondence and pushes a mutation that replaces those input bytes with a big-endian encoding of the second comparison operand, `repl` (this process is done on both the original/byte-swapped versions of the relevant values, to handle either byte order) This commit fixes a bit shifting bug (probably typo) that broke the replacement and made RQ unable to solve the comparison. Instead, we'll use copy_from_slice
1 parent b00894e commit e75d518

1 file changed

Lines changed: 3 additions & 17 deletions

File tree

crates/libafl/src/mutators/token_mutations.rs

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1076,8 +1076,7 @@ impl AflppRedQueen {
10761076

10771077
if buf_16 == pattern as u16 && another_buf_16 == another_pattern as u16 {
10781078
let mut cloned = buf.to_vec();
1079-
cloned[buf_idx + 1] = (repl & 0xff) as u8;
1080-
cloned[buf_idx] = ((repl >> 8) & 0xff) as u8;
1079+
cloned[buf_idx..(buf_idx+2)].copy_from_slice(&(repl as u16).to_be_bytes());
10811080
vec.push(cloned);
10821081
return Ok(true);
10831082
}
@@ -1091,12 +1090,8 @@ impl AflppRedQueen {
10911090
// println!("buf: {buf_32} {another_buf_32} {pattern} {another_pattern}");
10921091
if buf_32 == pattern as u32 && another_buf_32 == another_pattern as u32 {
10931092
let mut cloned = buf.to_vec();
1094-
cloned[buf_idx + 3] = (repl & 0xff) as u8;
1095-
cloned[buf_idx + 2] = ((repl >> 8) & 0xff) as u8;
1096-
cloned[buf_idx + 1] = ((repl >> 16) & 0xff) as u8;
1097-
cloned[buf_idx] = ((repl >> 24) & 0xff) as u8;
1093+
cloned[buf_idx..(buf_idx+4)].copy_from_slice(&(repl as u32).to_be_bytes());
10981094
vec.push(cloned);
1099-
11001095
return Ok(true);
11011096
}
11021097
}
@@ -1109,16 +1104,7 @@ impl AflppRedQueen {
11091104

11101105
if buf_64 == pattern && another_buf_64 == another_pattern {
11111106
let mut cloned = buf.to_vec();
1112-
1113-
cloned[buf_idx + 7] = (repl & 0xff) as u8;
1114-
cloned[buf_idx + 6] = ((repl >> 8) & 0xff) as u8;
1115-
cloned[buf_idx + 5] = ((repl >> 16) & 0xff) as u8;
1116-
cloned[buf_idx + 4] = ((repl >> 24) & 0xff) as u8;
1117-
cloned[buf_idx + 3] = ((repl >> 32) & 0xff) as u8;
1118-
cloned[buf_idx + 2] = ((repl >> 32) & 0xff) as u8;
1119-
cloned[buf_idx + 1] = ((repl >> 40) & 0xff) as u8;
1120-
cloned[buf_idx] = ((repl >> 48) & 0xff) as u8;
1121-
1107+
cloned[buf_idx..(buf_idx+8)].copy_from_slice(&repl.to_be_bytes());
11221108
vec.push(cloned);
11231109
return Ok(true);
11241110
}

0 commit comments

Comments
 (0)