Skip to content

Commit 49930b7

Browse files
committed
sethostname fixup
1 parent 34b1198 commit 49930b7

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

src/kernel/hostname.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use crate::memory::uaccess::cstr::UserCStr;
1+
use crate::memory::uaccess::copy_from_user_slice;
22
use crate::sched::current::current_task_shared;
33
use crate::sync::OnceLock;
44
use crate::sync::SpinLock;
@@ -30,9 +30,10 @@ pub async fn sys_sethostname(name_ptr: TUA<c_char>, name_len: usize) -> Result<u
3030
return Err(KernelError::NameTooLong);
3131
}
3232
let mut buf = vec![0u8; name_len];
33-
let name = UserCStr::from_ptr(name_ptr)
34-
.copy_from_user(&mut buf)
35-
.await?;
33+
copy_from_user_slice(name_ptr.to_untyped(), &mut buf).await?;
34+
let name = core::str::from_utf8(&buf)
35+
.map_err(|_| KernelError::InvalidValue)?
36+
.trim_end_matches('\0');
3637
*hostname().lock_save_irq() = name.to_string();
3738
Ok(0)
3839
}

0 commit comments

Comments
 (0)