Skip to content

Commit

Permalink
Mark buffer_{self_,}copy as unsafe, don't export them (#1207)
Browse files Browse the repository at this point in the history
  • Loading branch information
langston-barrett committed Apr 12, 2023
1 parent 1b9ffce commit 863a6b8
Show file tree
Hide file tree
Showing 4 changed files with 256 additions and 216 deletions.
22 changes: 15 additions & 7 deletions libafl/src/mutators/encoded_mutations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -241,10 +241,12 @@ where

input.codes_mut().resize(size + len, 0);
self.tmp_buf.resize(len, 0);
buffer_copy(&mut self.tmp_buf, input.codes(), from, 0, len);
unsafe {
buffer_copy(&mut self.tmp_buf, input.codes(), from, 0, len);

buffer_self_copy(input.codes_mut(), off, off + len, size - off);
buffer_copy(input.codes_mut(), &self.tmp_buf, 0, off, len);
buffer_self_copy(input.codes_mut(), off, off + len, size - off);
buffer_copy(input.codes_mut(), &self.tmp_buf, 0, off, len);
};

Ok(MutationResult::Mutated)
}
Expand Down Expand Up @@ -284,7 +286,9 @@ impl<S: HasRand> Mutator<EncodedInput, S> for EncodedCopyMutator {
let to = state.rand_mut().below(size as u64) as usize;
let len = 1 + state.rand_mut().below((size - max(from, to)) as u64) as usize;

buffer_self_copy(input.codes_mut(), from, to, len);
unsafe {
buffer_self_copy(input.codes_mut(), from, to, len);
}

Ok(MutationResult::Mutated)
}
Expand Down Expand Up @@ -356,8 +360,10 @@ where
}

input.codes_mut().resize(size + len, 0);
buffer_self_copy(input.codes_mut(), to, to + len, size - to);
buffer_copy(input.codes_mut(), other.codes(), from, to, len);
unsafe {
buffer_self_copy(input.codes_mut(), to, to + len, size - to);
buffer_copy(input.codes_mut(), other.codes(), from, to, len);
}

Ok(MutationResult::Mutated)
}
Expand Down Expand Up @@ -422,7 +428,9 @@ where
let mut other_testcase = state.corpus().get(idx)?.borrow_mut();
let other = other_testcase.load_input()?;

buffer_copy(input.codes_mut(), other.codes(), from, to, len);
unsafe {
buffer_copy(input.codes_mut(), other.codes(), from, to, len);
}

Ok(MutationResult::Mutated)
}
Expand Down
Loading

0 comments on commit 863a6b8

Please sign in to comment.