From d05f93215e7126dced3553dd0bae077177bca8db Mon Sep 17 00:00:00 2001 From: Dietmar Maurer Date: Fri, 28 Dec 2018 14:51:43 +0100 Subject: [PATCH] src/catar/encoder.rs: fix symlinks --- src/catar/encoder.rs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/catar/encoder.rs b/src/catar/encoder.rs index 5a44007e..e02d7ba5 100644 --- a/src/catar/encoder.rs +++ b/src/catar/encoder.rs @@ -187,11 +187,14 @@ impl CaTarEncoder { 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), }