Skip to content

issue 4189 memcpy oob #4378

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

Closed
wants to merge 4 commits into from
Closed
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
23 changes: 17 additions & 6 deletions src/libcore/vec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1960,6 +1960,9 @@ pub mod raw {
* may overlap.
*/
pub unsafe fn memcpy<T>(dst: &[mut T], src: &[const T], count: uint) {
assert dst.len() >= count;
assert src.len() >= count;

do as_mut_buf(dst) |p_dst, _len_dst| {
do as_const_buf(src) |p_src, _len_src| {
ptr::memcpy(p_dst, p_src, count)
Expand All @@ -1974,6 +1977,9 @@ pub mod raw {
* may overlap.
*/
pub unsafe fn memmove<T>(dst: &[mut T], src: &[const T], count: uint) {
assert dst.len() >= count;
assert src.len() >= count;

do as_mut_buf(dst) |p_dst, _len_dst| {
do as_const_buf(src) |p_src, _len_src| {
ptr::memmove(p_dst, p_src, count)
Expand Down Expand Up @@ -2035,9 +2041,7 @@ pub mod bytes {
* may not overlap.
*/
pub fn memcpy(dst: &[mut u8], src: &[const u8], count: uint) {
assert dst.len() >= count;
assert src.len() >= count;

// Bound checks are done at vec::raw::memcpy.
unsafe { vec::raw::memcpy(dst, src, count) }
}

Expand All @@ -2048,9 +2052,7 @@ pub mod bytes {
* may overlap.
*/
pub fn memmove(dst: &[mut u8], src: &[const u8], count: uint) {
assert dst.len() >= count;
assert src.len() >= count;

// Bound checks are done at vec::raw::memmove.
unsafe { vec::raw::memmove(dst, src, count) }
}
}
Expand Down Expand Up @@ -3730,6 +3732,15 @@ mod tests {
fail
}
}

#[test]
#[should_fail]
fn test_memcpy_oob() unsafe {
let a = [mut 1, 2, 3, 4];
let b = [1, 2, 3, 4, 5];
raw::memcpy(a, b, 5);
}

}

// Local Variables:
Expand Down