Skip to content
This repository was archived by the owner on Oct 26, 2021. It is now read-only.

Conversation

@haraldh
Copy link
Contributor

@haraldh haraldh commented Nov 26, 2020

  • fix(sallyport): mark copy_into_slice unsafe

    Cursor::copy_into_slice has to be unsafe, otherwise it is possible to
    fill in a slice of e.g. bools with invalid values using safe rust code.

    This patch also adds a test calling Cursor::copy_into_slice() and
    simplifies the method by removing a parameter and calling existing
    methods.

@haraldh haraldh requested a review from npmccallum as a code owner November 26, 2020 08:19
@enarxbot enarxbot requested review from ueno and whitebrandy November 26, 2020 08:19
@haraldh haraldh force-pushed the sallyport_into_slice branch from 1ffa4c4 to 411388e Compare November 26, 2020 08:32
@haraldh haraldh changed the title test(sallyport): add copy_into_slice test fix(sallyport): mark copy_into_slice unsafe Nov 26, 2020
@haraldh haraldh force-pushed the sallyport_into_slice branch from 411388e to 840f0b8 Compare November 26, 2020 08:34
@haraldh haraldh force-pushed the sallyport_into_slice branch from 840f0b8 to 087a62d Compare November 26, 2020 15:09
@haraldh haraldh marked this pull request as draft November 26, 2020 15:09
@haraldh haraldh force-pushed the sallyport_into_slice branch from 087a62d to 1004fb1 Compare November 26, 2020 15:23
@haraldh
Copy link
Contributor Author

haraldh commented Nov 26, 2020

Needs #188 first

@haraldh haraldh force-pushed the sallyport_into_slice branch 2 times, most recently from c57c5ff to 1856357 Compare November 30, 2020 15:40
@haraldh haraldh marked this pull request as ready for review November 30, 2020 15:41
connorkuehl
connorkuehl previously approved these changes Nov 30, 2020
Ok((c, dst))
}

/// Copies data from a slice into the cursor buffer using self.alloc().
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unrelated to this PR, but should this not be "copies from a cursor buffer into a slice"?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍


let mut slab_all = [0usize; 3];

let c = unsafe { c.copy_into_slice::<usize>(4, &mut slab_all, 3) }?;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is the src_len a 4 here? That is shorter than the total slab 1-3 values but longer than slab_all.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is the amount of elements the cursor should advance after copying.

`Cursor::copy_into_slice` has to be unsafe, otherwise it is possible to
fill in a slice of e.g. bools with invalid values using safe rust code.

This patch also adds a test calling `Cursor::copy_into_slice()` and
simplifies the method by removing a parameter and calling existing
methods.

Signed-off-by: Harald Hoyer <[email protected]>
@haraldh
Copy link
Contributor Author

haraldh commented Dec 1, 2020

Ok, I didn't see the forest because of all the trees... simplified the method by removing dst_len and documenting the arguments.

@enarxbot enarxbot merged commit e72a5c6 into enarx-archive:master Dec 1, 2020
@haraldh haraldh deleted the sallyport_into_slice branch December 2, 2020 09:02
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants