From dd0d23839ad4b2805cabf384271b722579fb4dca Mon Sep 17 00:00:00 2001 From: Valentin Lorentz Date: Sun, 22 Apr 2018 10:32:43 +0200 Subject: [PATCH] unlink: Add a nul-terminator after the file name before calling lstat. --- src/unlink/unlink.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/unlink/unlink.rs b/src/unlink/unlink.rs index 17e3d8d76..4dedcca71 100644 --- a/src/unlink/unlink.rs +++ b/src/unlink/unlink.rs @@ -22,6 +22,7 @@ use libc::{S_IFLNK, S_IFMT, S_IFREG}; use libc::{c_char, lstat, stat, unlink}; use std::io::{Error, ErrorKind}; use std::mem::uninitialized; +use std::ffi::CString; static NAME: &'static str = "unlink"; static VERSION: &'static str = env!("CARGO_PKG_VERSION"); @@ -69,9 +70,10 @@ pub fn uumain(args: Vec) -> i32 { let st_mode = { let mut buf: stat = unsafe { uninitialized() }; + let c_string = CString::new(matches.free[0].clone()).unwrap(); // unwrap() cannot fail, the string comes from argv so it cannot contain a \0. let result = unsafe { lstat( - matches.free[0].as_ptr() as *const c_char, + c_string.as_ptr(), &mut buf as *mut stat, ) };