Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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

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

Fixes: 0c89abf5ab3f ("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>

authored by

Thomas Weißschuh and committed by
Thomas Weißschuh
812f223f 3a866087

+12 -6
+12 -6
tools/include/nolibc/sys/wait.h
··· 65 65 66 66 switch (info.si_code) { 67 67 case 0: 68 - *status = 0; 68 + if (status) 69 + *status = 0; 69 70 break; 70 71 case CLD_EXITED: 71 - *status = (info.si_status & 0xff) << 8; 72 + if (status) 73 + *status = (info.si_status & 0xff) << 8; 72 74 break; 73 75 case CLD_KILLED: 74 - *status = info.si_status & 0x7f; 76 + if (status) 77 + *status = info.si_status & 0x7f; 75 78 break; 76 79 case CLD_DUMPED: 77 - *status = (info.si_status & 0x7f) | 0x80; 80 + if (status) 81 + *status = (info.si_status & 0x7f) | 0x80; 78 82 break; 79 83 case CLD_STOPPED: 80 84 case CLD_TRAPPED: 81 - *status = (info.si_status << 8) + 0x7f; 85 + if (status) 86 + *status = (info.si_status << 8) + 0x7f; 82 87 break; 83 88 case CLD_CONTINUED: 84 - *status = 0xffff; 89 + if (status) 90 + *status = 0xffff; 85 91 break; 86 92 default: 87 93 return -1;