From patchwork Mon Apr 6 18:39:21 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alistair Francis X-Patchwork-Id: 38753 Return-Path: X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from esa2.hgst.iphmx.com (esa2.hgst.iphmx.com [68.232.143.124]) by sourceware.org (Postfix) with ESMTPS id 0C79D385BF83 for ; Mon, 6 Apr 2020 18:47:06 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 0C79D385BF83 IronPort-SDR: 4yFYUgeNyqPcl4sF/0ShP7TlJoMLAXmMRCpDx9JU0yuOwBChxUgTWjnVa7R+KDTJWKwFp15rh/ 2bbEDiPqf5mxOU0uO8cKNn9/U62zqtb25k4nDtHO9TTw3Nke4joo0aJ5rT+WkHVOrMQ6ng6yVU MYME/3N/bsHmmatjSUXZ8Jo+B0JGVzy9LZr8A7tf/KEPbQDG09UbF2+V03OpVg8LPYIINAwcLj 2uTIkmcumcqbyTBRORb1tudyYfBX2RcYzfB/m2Ual4MZl7vn4JXVwVc6DkTdG01pqPAIyFQn40 YG0= X-IronPort-AV: E=Sophos;i="5.72,352,1580745600"; d="scan'208";a="237031395" Received: from h199-255-45-14.hgst.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 07 Apr 2020 02:47:30 +0800 IronPort-SDR: 72mefD2VGLgkjBENP+gZ90Q0uIzexpqSq+/TuYFl7NG/0H46g/zIXXVTZOCAaho4ctprHCw8mE POx+0XjG7AKrXelJ2KLsiiO/TtvxZKMVySf+dFXHFG4/YDAh6SEiDdl+lGPNUbuLYr63oHCWk/ zou6TYQT/ewXu8GgU9UMaGPCtKszE0zTMsLdoS4x02LEu6HJhxPRlWDQR4ow4mF7Ed7cJ1qFal 17NY6bcS+p28zadXuLKnui/ssUT8OtFwSpjzPuC3dFPovRD7YUu2Zy8xZaOfXiFLK90xxnfIC+ NRBEJx06yDhtFG7XJV9kh8zl Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 06 Apr 2020 11:38:22 -0700 IronPort-SDR: 2btqriX1OWxy8XEWkZ+ip8XdYSU94OMa8MxNUNQ5wf/BuYPPY9ZTcQ9K90s8SBUemZICgLWaPG 0R5qukrtrowFz0NTyQKgDGmQppTdNjvv4UoPmqtyXOz3mAFYqAxwtfxQ/8ihmXkJDCQNFE0rMm nzy7a9lHSgkgTXLPlVeZ2VzYikxbKSN4NCoNQVNLaEWsfem9I5tYRpUH0a2/XnBrk6VWVok2H8 naAssHje8alJDtAhJoKX8a3bxYARb94rMlgVn1bt6Rjg4VxhQwkyKMonOxJCs4IOnQCvl7+B6+ Hq8= WDCIronportException: Internal Received: from wdapacbjl0003.my.asia.wdc.com (HELO risc6-mainframe.hgst.com) ([10.86.55.90]) by uls-op-cesaip02.wdc.com with ESMTP; 06 Apr 2020 11:47:05 -0700 From: Alistair Francis To: libc-alpha@sourceware.org Cc: alistair23@gmail.com, Alistair Francis Subject: [PATCH] linux: wait4: Fix incorrect return value comparison Date: Mon, 6 Apr 2020 11:39:21 -0700 Message-Id: <20200406183921.530591-1-alistair.francis@wdc.com> X-Mailer: git-send-email 2.26.0 MIME-Version: 1.0 X-Spam-Status: No, score=-24.9 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: Mon, 06 Apr 2020 18:47:08 -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 | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/sysdeps/unix/sysv/linux/wait4.c b/sysdeps/unix/sysv/linux/wait4.c index d14bd4da27..796691eb2b 100644 --- a/sysdeps/unix/sysv/linux/wait4.c +++ b/sysdeps/unix/sysv/linux/wait4.c @@ -32,10 +32,7 @@ __wait4_time64 (pid_t pid, int *stat_loc, int options, struct __rusage64 *usage) struct __rusage32 usage32; pid_t ret = SYSCALL_CANCEL (wait4, pid, stat_loc, options, &usage32); - if (ret != 0) - return ret; - - if (usage != NULL) + if (ret > 0 && usage != NULL) rusage32_to_rusage64 (&usage32, usage); return ret; @@ -119,10 +116,8 @@ __wait4 (pid_t pid, int *stat_loc, int options, struct rusage *usage) ret = __wait4_time64 (pid, stat_loc, options, &usage64); - if (ret != 0) - return ret; - - rusage64_to_rusage (&usage64, usage); + if (ret > 0 && usage != NULL) + rusage64_to_rusage (&usage64, usage); return ret; }