From patchwork Thu Apr 9 20:11:53 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alistair Francis X-Patchwork-Id: 38798 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 04238385DC03 for ; Thu, 9 Apr 2020 20:19:51 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 04238385DC03 IronPort-SDR: ypTSRK0IX0xHhob4DT3E0IMggGi4lYRNv6R9XilRNoWHqKCTLndjVVyxu++7qrHOPIztZGCuAJ tCxkBzXf2aaUaWCt7oYztdGZREQp0oQcrM8/iTA66FP5vl422jkhBBv/b0Y2Uru89PXJZblXzB PfC3cNuUSK4l9IlLGfCe3/fkJ2NK1gt6ZPqVpBJo6jOkHmBcrhFfYEGOAz2qkjhjDON/zbknmg rykfssEPFPwBpcUyxwKP+iXpO+G0xuDBMFOaTR85ueEHqoRn2bPLgazn71R7PqWXhGLLlU9cvL dvM= X-IronPort-AV: E=Sophos;i="5.72,363,1580745600"; d="scan'208";a="139316536" Received: from h199-255-45-15.hgst.com (HELO uls-op-cesaep02.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 10 Apr 2020 04:19:44 +0800 IronPort-SDR: 239OmDvyPE5e/52O+6/Y/QErwMB6xvckGNQ7+B/LSryPERo3iCZvxHLZr0DZ+5EC/6WGVN0ej2 b3lcCRl2xDDNLKL5VKp3rgqEDeZDr8Q8JCtDmWSyqY6g2KDyy7FbZ5cn/OFS6ApH1Bqkrc59du bPEq96+N5Vdp0rkjECdGZc4En5vvx6GGKpKFsoWKc1RRwkPCNxCnk2AUqmajHU/F2b+6GO23V8 9Y5PUifvi1FUkN7T4amLejN42H1P71s6n9Zt0J4T/UI5Z9YcDobi6xsvNp2hSpQYPWgIItPMUJ nrVZxj0COEDG4Yp7BNyNg7Z7 Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 09 Apr 2020 13:10:23 -0700 IronPort-SDR: tNAsPniOFCNyGuAwJLogfrdPyVt1V849159LC0icB8cTU9jSrC808CteU41bpxoNBQ+K+k4h4b oeecehMTaj1jIzrzezM3F8gpd3OLcThsN3KXPRHn+3I7Qh6Gt9B3QSr3G5+P0o19PLxcAyVvAk Xx/CP7mB450wfLheTNcalti2+uVt6icWtUiMoDQhaFFetPnYHDGK8H7HAxl4BKfiPb3k2bi3y5 jCVSjehHcDX/LYLwwUv5WZBmve6hN5iyPyt6sPgoXnxe9pKDWH+NyyqJOxcrvbz9kks0jLYIhN 1PE= WDCIronportException: Internal Received: from 5zs6pc2.ad.shared (HELO risc6-mainframe.hgst.com) ([10.86.55.151]) by uls-op-cesaip02.wdc.com with ESMTP; 09 Apr 2020 13:19:43 -0700 From: Alistair Francis To: libc-alpha@sourceware.org Cc: alistair23@gmail.com, Alistair Francis Subject: [PATCH v3 1/2] linux: wait4: Fix incorrect return value comparison Date: Thu, 9 Apr 2020 13:11:53 -0700 Message-Id: <20200409201154.3365671-1-alistair.francis@wdc.com> X-Mailer: git-send-email 2.26.0 MIME-Version: 1.0 X-Spam-Status: No, score=-25.3 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: Thu, 09 Apr 2020 20:19:53 -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 | 32 ++++++++++++++++++++------------ 1 file changed, 20 insertions(+), 12 deletions(-) diff --git a/sysdeps/unix/sysv/linux/wait4.c b/sysdeps/unix/sysv/linux/wait4.c index d14bd4da27..21eb154b72 100644 --- a/sysdeps/unix/sysv/linux/wait4.c +++ b/sysdeps/unix/sysv/linux/wait4.c @@ -29,14 +29,18 @@ __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); - - if (ret != 0) - return ret; + pid_t ret; if (usage != NULL) - rusage32_to_rusage64 (&usage32, usage); + { + struct __rusage32 usage32; + ret = SYSCALL_CANCEL (wait4, pid, stat_loc, options, &usage32); + + if (ret > 0) + rusage32_to_rusage64 (&usage32, usage); + } + else + ret = SYSCALL_CANCEL (wait4, pid, stat_loc, options, NULL); return ret; # endif @@ -114,15 +118,19 @@ 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; }