Browse Source

Handle the null case in realpath

The destination pointer might be null, in which case we are supposed to
malloc some memory for it:
https://man7.org/linux/man-pages/man3/realpath.3.html
pull/5/head
AzureMarker 3 years ago
parent
commit
f4443c85e1
No known key found for this signature in database
GPG Key ID: 47A133F3BF9D03D3
  1. 10
      src/lib.rs

10
src/lib.rs

@ -24,9 +24,15 @@ extern "C" fn posix_memalign(
#[no_mangle] #[no_mangle]
unsafe extern "C" fn realpath( unsafe extern "C" fn realpath(
path: *const libc::c_char, path: *const libc::c_char,
resolved_path: *mut libc::c_char, mut resolved_path: *mut libc::c_char,
) -> *mut libc::c_char { ) -> *mut libc::c_char {
libc::memcpy(resolved_path as _, path as _, libc::strlen(path)); let path_len = libc::strlen(path);
if resolved_path.is_null() {
resolved_path = libc::malloc(path_len + 1) as _;
}
libc::strncpy(resolved_path as _, path as _, path_len + 1);
resolved_path resolved_path
} }

Loading…
Cancel
Save