Skip to content

Commit

Permalink
Merge pull request syswonder#166 from ken4647/dev
Browse files Browse the repository at this point in the history
Fix null pointer dereference when wstatus is NULL in sys_wait4
  • Loading branch information
lhw2002426 authored Jan 30, 2025
2 parents eb2cb0a + d38806b commit 933ec44
Showing 1 changed file with 14 additions and 10 deletions.
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

0 comments on commit 933ec44

Please sign in to comment.