From patchwork Tue Apr 7 05:40:10 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alistair Francis X-Patchwork-Id: 38765 Return-Path: X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from esa3.hgst.iphmx.com (esa3.hgst.iphmx.com [216.71.153.141]) by sourceware.org (Postfix) with ESMTPS id 03064385BF83 for ; Tue, 7 Apr 2020 05:47:56 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 03064385BF83 IronPort-SDR: 60jp5EnjYfQ1WE69uvcu9oeXUboVcLKvBVENf6HgHnFtzKS3WCDYyuJfeU1FtIGHdRvClwsSdY L9NMSYSSVyJAwIBlC968GPu5F5OYG6VO+p9sNYYMSQQpbIALa53QkoQ100MJVlxR9DCDHsR5pc SmhvSP5vp0WL8HtEXVZyN8PtlTfCeLXRZ61RPbmAmbh3t4PVY0PpWAVC8OnZCC6kSRXQFYPzpN oKyw2k6auyiSBnh/a+CyYMuuK0SHl8wHPkQn8DEhhDv+G4W2lgyBUdKYGJxUp2qFwQY0t8N56b Mh4= X-IronPort-AV: E=Sophos;i="5.72,353,1580745600"; d="scan'208";a="139043990" Received: from uls-op-cesaip01.wdc.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 07 Apr 2020 13:47:56 +0800 IronPort-SDR: iFIVK2xcXvx9JkLC9Swpl9gxmx4j9BjL44xonhMWEfWR/hX1vwHUca4toAkh+CwLvr2Wg3M/Hl +K16HL4RZSZs/TGaFf0fOHhsOxoO95lDp5uPDgWC7pY0PZADK6xHq+a9db4oeNDwiieMndhgtG 2ZbeTzcZ28NPpP3YwYURSLREMxr8zxlsCCDy4B3Iuerkq2o85pK/UruVt6esuVWdf1BDIY2du1 pFTSN/uducmpmxim/8lIu72NSP++l8XZ6VFNdH2HrtHkGOaWQwv1x3Q5CeynF/0I0Sqgmxb0W0 ZB4qN4xAJ21dFfQ5RQ6oqD3f Received: from uls-op-cesaip01.wdc.com ([10.248.3.36]) by uls-op-cesaep01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 06 Apr 2020 22:39:12 -0700 IronPort-SDR: +hMXHLoEHW5+p5jfY/5bAYwJzsF1YzG8zPZzLhfQM3gBpBfUHaAKCqFmvYIQF0+ExSM/sE/I6v E/0n7cTOe+1oVMfiz5wUtIorG3N+xh+EzmTGCydrR+E4vpNhfdn7uIS/jQqMTdtVdTBg0WN+7X dDqoL+KVkBVF5ooWHxbz/zMauTbzRhcNS1tzu2M7bV6zz8SBcnWKBb7q1GIerNP88PsMQQQAg/ WzWRI3VN73HXBFfW2QokoI7rbULZodGCo8F5reS1PPy9YO5s57Xflb5UMsF8luhpUYWlmQfcmH zsw= WDCIronportException: Internal Received: from cnf006056.ad.shared (HELO risc6-mainframe.hgst.com) ([10.86.55.66]) by uls-op-cesaip01.wdc.com with ESMTP; 06 Apr 2020 22:47:55 -0700 From: Alistair Francis To: libc-alpha@sourceware.org Cc: alistair23@gmail.com, Alistair Francis Subject: [PATCH v2] linux: wait4: Fix incorrect return value comparison Date: Mon, 6 Apr 2020 22:40:10 -0700 Message-Id: <20200407054010.2573333-1-alistair.francis@wdc.com> X-Mailer: git-send-email 2.26.0 MIME-Version: 1.0 X-Spam-Status: No, score=-24.6 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 07 Apr 2020 05:47:58 -0000 Path 600f00b "linux: Use long time_t for wait4/getrusage" introduced two bugs: - The usage32 struct was set if the wait4 syscall had an error. - For 32-bit systems the usage struct was set even if it was specified as NULL. This patch fixes the two issues. Signed-off-by: Alistair Francis --- sysdeps/unix/sysv/linux/wait4.c | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/sysdeps/unix/sysv/linux/wait4.c b/sysdeps/unix/sysv/linux/wait4.c index d14bd4da27..973af48951 100644 --- a/sysdeps/unix/sysv/linux/wait4.c +++ b/sysdeps/unix/sysv/linux/wait4.c @@ -29,14 +29,16 @@ __wait4_time64 (pid_t pid, int *stat_loc, int options, struct __rusage64 *usage) # if __KERNEL_OLD_TIMEVAL_MATCHES_TIMEVAL64 return SYSCALL_CANCEL (wait4, pid, stat_loc, options, usage); # else - struct __rusage32 usage32; - pid_t ret = SYSCALL_CANCEL (wait4, pid, stat_loc, options, &usage32); + pid_t ret; - if (ret != 0) - return ret; + if (usage != NULL) { + struct __rusage32 usage32; + ret = SYSCALL_CANCEL (wait4, pid, stat_loc, options, &usage32); - if (usage != NULL) - rusage32_to_rusage64 (&usage32, usage); + if (ret > 0) + rusage32_to_rusage64 (&usage32, usage); + } else + ret = SYSCALL_CANCEL (wait4, pid, stat_loc, options, NULL); return ret; # endif @@ -114,15 +116,17 @@ libc_hidden_def (__wait4_time64) pid_t __wait4 (pid_t pid, int *stat_loc, int options, struct rusage *usage) { - pid_t ret ; - struct __rusage64 usage64; + pid_t ret; - ret = __wait4_time64 (pid, stat_loc, options, &usage64); + if (usage != NULL) { + struct __rusage64 usage64; - if (ret != 0) - return ret; + ret = __wait4_time64 (pid, stat_loc, options, &usage64); - rusage64_to_rusage (&usage64, usage); + if (ret > 0) + rusage64_to_rusage (&usage64, usage); + } else + ret = __wait4_time64 (pid, stat_loc, options, NULL); return ret; }