tools/nolibc: handle NULL wstatus argument to waitpid()

[ Upstream commit 812f223fe9be03dc22abb85240b6f075135d2386 ]

wstatus is allowed to be NULL. Avoid a segmentation fault in this case.

Fixes: 0c89abf5ab ("tools/nolibc: implement waitpid() in terms of waitid()")
Signed-off-by: Thomas Weißschuh <thomas.weissschuh@linutronix.de>
Acked-by: Willy Tarreau <w@1wt.eu>
Signed-off-by: Thomas Weißschuh <linux@weissschuh.net>
Signed-off-by: Sasha Levin <sashal@kernel.org>
This commit is contained in:
Thomas Weißschuh 2025-09-26 16:26:58 +02:00 committed by Greg Kroah-Hartman
parent 19e359b18a
commit e506f976c9
1 changed files with 12 additions and 6 deletions

View File

@ -65,23 +65,29 @@ pid_t waitpid(pid_t pid, int *status, int options)
switch (info.si_code) { switch (info.si_code) {
case 0: case 0:
*status = 0; if (status)
*status = 0;
break; break;
case CLD_EXITED: case CLD_EXITED:
*status = (info.si_status & 0xff) << 8; if (status)
*status = (info.si_status & 0xff) << 8;
break; break;
case CLD_KILLED: case CLD_KILLED:
*status = info.si_status & 0x7f; if (status)
*status = info.si_status & 0x7f;
break; break;
case CLD_DUMPED: case CLD_DUMPED:
*status = (info.si_status & 0x7f) | 0x80; if (status)
*status = (info.si_status & 0x7f) | 0x80;
break; break;
case CLD_STOPPED: case CLD_STOPPED:
case CLD_TRAPPED: case CLD_TRAPPED:
*status = (info.si_status << 8) + 0x7f; if (status)
*status = (info.si_status << 8) + 0x7f;
break; break;
case CLD_CONTINUED: case CLD_CONTINUED:
*status = 0xffff; if (status)
*status = 0xffff;
break; break;
default: default:
return -1; return -1;