Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit e0d984c2 authored by Treehugger Robot's avatar Treehugger Robot Committed by Automerger Merge Worker
Browse files

Merge "Unset FDSan tag when converting handle into other types" into main am:...

Merge "Unset FDSan tag when converting handle into other types" into main am: bbe31e3a am: 7bcef3ad

Original change: https://android-review.googlesource.com/c/platform/frameworks/native/+/3316994



Change-Id: I6a4da61eccf113e2e3af6790a40f4b3ab7c4a009
Signed-off-by: default avatarAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
parents 839f298d 7bcef3ad
Loading
Loading
Loading
Loading
+29 −0
Original line number Diff line number Diff line
@@ -85,6 +85,12 @@ impl NativeHandle {

    /// Destroys the `NativeHandle`, taking ownership of the file descriptors it contained.
    pub fn into_fds(self) -> Vec<OwnedFd> {
        // Unset FDSan tag since this `native_handle_t` is no longer the owner of the file
        // descriptors after this function.
        // SAFETY: Our wrapped `native_handle_t` pointer is always valid.
        unsafe {
            ffi::native_handle_unset_fdsan_tag(self.as_ref());
        }
        let fds = self.data()[..self.fd_count()]
            .iter()
            .map(|fd| {
@@ -260,6 +266,29 @@ mod test {
        drop(cloned);
    }

    #[test]
    fn to_fds() {
        let file = File::open("/dev/null").unwrap();
        let original = NativeHandle::new(vec![file.into()], &[42]).unwrap();
        assert_eq!(original.ints(), &[42]);
        assert_eq!(original.fds().len(), 1);

        let fds = original.into_fds();
        assert_eq!(fds.len(), 1);
    }

    #[test]
    fn to_aidl() {
        let file = File::open("/dev/null").unwrap();
        let original = NativeHandle::new(vec![file.into()], &[42]).unwrap();
        assert_eq!(original.ints(), &[42]);
        assert_eq!(original.fds().len(), 1);

        let aidl = AidlNativeHandle::from(original);
        assert_eq!(&aidl.ints, &[42]);
        assert_eq!(aidl.fds.len(), 1);
    }

    #[test]
    fn to_from_aidl() {
        let file = File::open("/dev/null").unwrap();