Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix null pointer dereference when wstatus is NULL in sys_wait4 #166

Merged
merged 1 commit into from
Jan 30, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 14 additions & 10 deletions api/ruxos_posix_api/src/imp/task.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,11 +97,13 @@ pub unsafe fn sys_wait4(
let mut process_map = PROCESS_MAP.lock();
if let Some(task) = process_map.get(&(pid as u64)) {
if task.state() == ruxtask::task::TaskState::Exited {
unsafe {
// lower 8 bits of exit_code is the signal number, while upper 8 bits of exit_code is the exit status
// according to "bits/waitstatus.h" in glibc source code.
// TODO: add signal number to wstatus
wstatus.write(task.exit_code() << 8);
if !wstatus.is_null() {
unsafe {
// lower 8 bits of exit_code is the signal number, while upper 8 bits of exit_code is the exit status
// according to "bits/waitstatus.h" in glibc source code.
// TODO: add signal number to wstatus
wstatus.write(task.exit_code() << 8);
}
}
process_map.remove(&(pid as u64));
return pid;
Expand Down Expand Up @@ -129,11 +131,13 @@ pub unsafe fn sys_wait4(
&& task.state() == ruxtask::task::TaskState::Exited
{
// add to to_remove list
unsafe {
// lower 8 bits of exit_code is the signal number, while upper 8 bits of exit_code is the exit status
// according to "bits/waitstatus.h" in glibc source code.
// TODO: add signal number to wstatus
wstatus.write(task.exit_code() << 8);
if !wstatus.is_null() {
unsafe {
// lower 8 bits of exit_code is the signal number, while upper 8 bits of exit_code is the exit status
// according to "bits/waitstatus.h" in glibc source code.
// TODO: add signal number to wstatus
wstatus.write(task.exit_code() << 8);
}
}
let _ = to_remove.insert(*child_pid);
break;
Expand Down
Loading