Don't crash when nullptr paired with len = 0

This commit is contained in:
topjohnwu
2022-09-15 16:56:22 -07:00
parent c6646efe68
commit af99c1b843
3 changed files with 30 additions and 10 deletions

View File

@@ -7,10 +7,11 @@ use crate::{bfmt_cstr, errno, xopen};
mod unsafe_impl {
use std::ffi::CStr;
use std::slice;
use libc::c_char;
use crate::slice_from_ptr_mut;
#[no_mangle]
pub unsafe extern "C" fn read_link(path: *const c_char, buf: *mut u8, bufsz: usize) -> isize {
let r = libc::readlink(path, buf.cast(), bufsz - 1);
@@ -22,7 +23,7 @@ mod unsafe_impl {
#[no_mangle]
unsafe extern "C" fn canonical_path(path: *const c_char, buf: *mut u8, bufsz: usize) -> isize {
super::canonical_path(CStr::from_ptr(path), slice::from_raw_parts_mut(buf, bufsz))
super::canonical_path(CStr::from_ptr(path), slice_from_ptr_mut(buf, bufsz))
}
}