]> git.proxmox.com Git - proxmox-backup.git/commitdiff
src/catar/encoder.rs: fix symlinks
authorDietmar Maurer <dietmar@proxmox.com>
Fri, 28 Dec 2018 13:51:43 +0000 (14:51 +0100)
committerDietmar Maurer <dietmar@proxmox.com>
Fri, 28 Dec 2018 14:02:42 +0000 (15:02 +0100)
src/catar/encoder.rs

index 5a44007e052a54509f3abc2602744d4e434a3198..e02d7ba502a9ca2075c659ec7ac807b5ecf0c4ce 100644 (file)
@@ -187,11 +187,14 @@ impl <W: Write> CaTarEncoder<W> {
                 let mut buffer = [0u8; libc::PATH_MAX as usize];
 
                 let res = filename.with_nix_path(|cstr| {
-                    unsafe { libc::readlink(cstr.as_ptr(), buffer.as_mut_ptr() as *mut libc::c_char, buffer.len()) }
+                    unsafe { libc::readlinkat(rawfd, cstr.as_ptr(), buffer.as_mut_ptr() as *mut libc::c_char, buffer.len()-1) }
                 })?;
 
                 match Errno::result(res) {
-                    Ok(len) => self.encode_symlink(&buffer[..(len as usize)], &stat)?,
+                    Ok(len) => {
+                        buffer[len as usize] = 0u8; // add Nul byte
+                        self.encode_symlink(&buffer[..((len+1) as usize)], &stat)?
+                    }
                     Err(nix::Error::Sys(Errno::ENOENT)) => self.report_vanished_file(&self.current_path)?,
                     Err(err) => bail!("readlink {:?} failed - {}", self.current_path, err),
                 }