public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
* [PATCH v2] linux: wait4: Fix incorrect return value comparison
@ 2020-04-07  5:40 Alistair Francis
  2020-04-07  7:35 ` Andreas Schwab
  2020-04-07 11:23 ` Florian Weimer
  0 siblings, 2 replies; 8+ messages in thread
From: Alistair Francis @ 2020-04-07  5:40 UTC (permalink / raw)
  To: libc-alpha; +Cc: alistair23, Alistair Francis

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 <alistair.francis@wdc.com>
---
 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;
 }
-- 
2.26.0


^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2020-04-09 20:21 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-04-07  5:40 [PATCH v2] linux: wait4: Fix incorrect return value comparison Alistair Francis
2020-04-07  7:35 ` Andreas Schwab
2020-04-07 11:23 ` Florian Weimer
2020-04-07 13:24   ` Adhemerval Zanella
2020-04-07 14:47     ` Alistair Francis
2020-04-09 15:35       ` Florian Weimer
2020-04-09 15:41         ` Adhemerval Zanella
2020-04-09 20:13         ` Alistair Francis

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).