Skip to content

Commit

Permalink
fix(sys): rust to c string conversion on Linux
Browse files Browse the repository at this point in the history
  • Loading branch information
XOR-op committed Nov 19, 2024
1 parent 041eab8 commit 298caf8
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions boltconn/src/platform/sys/linux_sys.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use crate::platform::{
};
use ipnet::IpNet;
use libc::{c_int, socklen_t, O_RDWR};
use std::ffi::CStr;
use std::ffi::{CStr, CString};
use std::fs::{File, OpenOptions};
use std::io::Write;
use std::net::{IpAddr, Ipv4Addr};
Expand Down Expand Up @@ -139,7 +139,7 @@ impl Drop for SystemDnsHandle {

pub fn get_user_info() -> Option<UserInfo> {
let (name, user_info) = if let Ok(n) = std::env::var("SUDO_USER") {
let user_info = unsafe { libc::getpwnam(n.as_ptr() as *const i8) };
let user_info = unsafe { libc::getpwnam(CString::new(n.clone()).ok()?.as_ptr()) };
(n, user_info)
} else {
let user_name = unsafe { libc::getlogin() };
Expand Down

0 comments on commit 298caf8

Please sign in to comment.