1
Fork 0
mirror of https://github.com/RGBCube/uutils-coreutils synced 2025-07-31 13:07:46 +00:00

unlink: Add a nul-terminator after the file name before calling lstat.

This commit is contained in:
Valentin Lorentz 2018-04-22 10:32:43 +02:00
parent 5f9bb70422
commit dd0d23839a

View file

@ -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<String>) -> 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,
)
};