]> git.proxmox.com Git - pxar.git/commitdiff
use CStr for XAttr names
authorWolfgang Bumiller <w.bumiller@proxmox.com>
Fri, 24 Apr 2020 08:41:39 +0000 (10:41 +0200)
committerWolfgang Bumiller <w.bumiller@proxmox.com>
Fri, 24 Apr 2020 08:41:39 +0000 (10:41 +0200)
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
src/format.rs

index ea259125657a7dd6ab785e422091aa1452bda917..d1635ecc0b0e975cf99969d76dbd93bd87c5560c 100644 (file)
@@ -6,7 +6,7 @@
 //! item data.
 
 use std::cmp::Ordering;
-use std::ffi::OsStr;
+use std::ffi::{CStr, OsStr};
 use std::io;
 use std::mem::size_of;
 use std::os::unix::ffi::OsStrExt;
@@ -310,8 +310,10 @@ impl XAttr {
         }
     }
 
-    pub fn name(&self) -> &[u8] {
-        &self.data[..self.name_len]
+    pub fn name(&self) -> &CStr {
+        unsafe {
+            CStr::from_bytes_with_nul_unchecked(&self.data[..self.name_len+1])
+        }
     }
 
     pub fn value(&self) -> &[u8] {