From e8958c6b5c5910f08cd6de6ee30e15fba057d7c4 Mon Sep 17 00:00:00 2001 From: vvb2060 Date: Mon, 3 Mar 2025 00:24:10 +0800 Subject: [PATCH] get_secontext: ignore ENODATA --- native/src/base/files.rs | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/native/src/base/files.rs b/native/src/base/files.rs index 9c384ce7c..175c33aec 100644 --- a/native/src/base/files.rs +++ b/native/src/base/files.rs @@ -733,10 +733,12 @@ impl FsPath { XATTR_NAME_SELINUX.as_ptr().cast(), con.as_mut_ptr().cast(), con.capacity(), - ) - .check_os_err()?; + ); if sz < 1 { con.clear(); + if *errno() != libc::ENODATA { + return Err(io::Error::last_os_error()); + } } else { con.set_len((sz - 1) as usize); } @@ -840,9 +842,14 @@ pub fn fd_get_attr(fd: RawFd) -> io::Result { XATTR_NAME_SELINUX.as_ptr().cast(), attr.con.as_mut_ptr().cast(), attr.con.capacity(), - ) - .check_os_err()?; - attr.con.set_len((sz - 1) as usize); + ); + if sz < 1 { + if *errno() != libc::ENODATA { + return Err(io::Error::last_os_error()); + } + } else { + attr.con.set_len((sz - 1) as usize); + } } } Ok(attr)