From patchwork Fri Apr 10 18:55:11 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alistair Francis X-Patchwork-Id: 38800 Return-Path: X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from esa1.hgst.iphmx.com (esa1.hgst.iphmx.com [68.232.141.245]) by sourceware.org (Postfix) with ESMTPS id D8FE3385B835 for ; Fri, 10 Apr 2020 19:03:05 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org D8FE3385B835 IronPort-SDR: B66s8jiK/YAYbI4knO2LTy7x6yAcupEaaLg8zeo3tHU2Qb63wUsFMk9PyESYhe6OZ4ufCnfIYk jQW4npJPsA9v3zoHTMU3RHBixWrlsLjnZ54OLrxhfyh9sKn7kqtnoDaYQFOT9Ag2a/FTMsOB0x iDHn6xpuVzt3nO/NnPNd3krC0EWPVS/K5PP6jqa8d0pM0+NIgCre8ve80GcQjE7GezrcWf7uJy UvJIXumbQgMArSQUTQgN72L6g5eKt/3/wp/g7sJiYN+h5Z0x3l6N/8Nbuhi4uXCSgAmLdyBJEj sBU= X-IronPort-AV: E=Sophos;i="5.72,367,1580745600"; d="scan'208";a="243684708" Received: from uls-op-cesaip01.wdc.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 11 Apr 2020 03:03:04 +0800 IronPort-SDR: o4Rm7doQOIJjWWLoeeG7MOhxsiPtV9MzGj5hPZNA9+peIVGQOQpKfii0D2UtxHDQNTv/Z/K5KW UH9x0b9AtN6cCEj/ObdA/BXpsBHHgeiIv3RxGNBHQqVn+vDDu6j6jp6LQix81EazHe6zRoSVY8 uCXOzGtu1XaGrX0M2Ilj+jhUicpHqdfmmxAEcJ3GL7AX/zc7A27kEjdlsJp6LlYxmqR7ZcShEC n7tXTFrxo2qi6SsRvwD7K+SCjdRg1UGaAjitetmNkbg/43ZP6gaIPaudyGvGLsvLHQYoWj9NSt H86fBXZQGLPYDi/8DCMN5exw 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; 10 Apr 2020 11:54:14 -0700 IronPort-SDR: Si/deYpIwejZW1VjfL56GOdKuWEkB36rf4eA7AvodTiMPhXMGpv4qS76Jx78mkYbTJ5apd1YmZ tD2jlcIFqX0gX7p9CLw3y8/K9DH52xK9kQ6NLk+APG75ZoCijLhzmuqrjfhEv0xrdfs2T5uxAJ Gdw45RTrmvzwfqvHgQhfiarLSTB5YhTwIpTt3x7F9PKDsKMzkV0SN751HbB0Uu/OQKdk+Vr1yn Y8s6uc1/yBf1ytRYIzmH6NFSkbpWD+1TDIzQa8XNXwntlWr1vfwi0RjhcqC8d8l0AcNJJjuJ/c i0M= WDCIronportException: Internal Received: from phd004806.ad.shared (HELO risc6-mainframe.hgst.com) ([10.86.55.150]) by uls-op-cesaip01.wdc.com with ESMTP; 10 Apr 2020 12:03:04 -0700 From: Alistair Francis To: libc-alpha@sourceware.org Cc: alistair23@gmail.com, Alistair Francis Subject: [PATCH v4 1/2] linux: wait4: Fix incorrect return value comparison Date: Fri, 10 Apr 2020 11:55:11 -0700 Message-Id: <20200410185513.1284043-1-alistair.francis@wdc.com> X-Mailer: git-send-email 2.26.0 MIME-Version: 1.0 X-Spam-Status: No, score=-24.5 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: Fri, 10 Apr 2020 19:03:07 -0000 Patch 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. --- sysdeps/unix/sysv/linux/wait4.c | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/sysdeps/unix/sysv/linux/wait4.c b/sysdeps/unix/sysv/linux/wait4.c index d14bd4da27..44c55f60fe 100644 --- a/sysdeps/unix/sysv/linux/wait4.c +++ b/sysdeps/unix/sysv/linux/wait4.c @@ -29,13 +29,13 @@ __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 + pid_t ret; struct __rusage32 usage32; - pid_t ret = SYSCALL_CANCEL (wait4, pid, stat_loc, options, &usage32); - if (ret != 0) - return ret; + ret = SYSCALL_CANCEL (wait4, pid, stat_loc, options, + usage != NULL ? &usage32 : NULL); - if (usage != NULL) + if (ret > 0 && usage != NULL) rusage32_to_rusage64 (&usage32, usage); return ret; @@ -114,15 +114,14 @@ libc_hidden_def (__wait4_time64) pid_t __wait4 (pid_t pid, int *stat_loc, int options, struct rusage *usage) { - pid_t ret ; + pid_t ret; struct __rusage64 usage64; - ret = __wait4_time64 (pid, stat_loc, options, &usage64); + ret = __wait4_time64 (pid, stat_loc, options, + usage != NULL ? &usage64 : NULL); - if (ret != 0) - return ret; - - rusage64_to_rusage (&usage64, usage); + if (ret > 0 && usage != 0) + rusage64_to_rusage (&usage64, usage); return ret; }