Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/bin/sh Avoid a core dump if a child process that is not one ...



details:   https://anonhg.NetBSD.org/src/rev/be0ce06b91f1
branches:  trunk
changeset: 744585:be0ce06b91f1
user:      kre <kre%NetBSD.org@localhost>
date:      Fri Feb 07 02:06:12 2020 +0000

description:
Avoid a core dump if a child process that is not one of our
children happens to exit while we are waiting for another child
to exit.

This can happen with code like

        sh -c '
                sleep 5 &
                exec sh -c "sleep 10 & wait !$"
              '

when the inner "sh" is waiting for the 10 second sleep to be
done, the 5 second sleep started earlier terminates.   It is
a child of our process, as the inner shell is the same process
as the outer one, but not a known child (the inner shell has no
idea what the outer one did before it started).

This was observed in the wild by Martijn Dekker (where the outer
shell was bash but that's irrelevant).

XXX pullup -9

diffstat:

 bin/sh/jobs.c |  7 +++++--
 1 files changed, 5 insertions(+), 2 deletions(-)

diffs (28 lines):

diff -r 2282158e0115 -r be0ce06b91f1 bin/sh/jobs.c
--- a/bin/sh/jobs.c     Fri Feb 07 01:25:08 2020 +0000
+++ b/bin/sh/jobs.c     Fri Feb 07 02:06:12 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: jobs.c,v 1.106 2019/03/26 13:32:26 kre Exp $   */
+/*     $NetBSD: jobs.c,v 1.107 2020/02/07 02:06:12 kre Exp $   */
 
 /*-
  * Copyright (c) 1991, 1993
@@ -37,7 +37,7 @@
 #if 0
 static char sccsid[] = "@(#)jobs.c     8.5 (Berkeley) 5/4/95";
 #else
-__RCSID("$NetBSD: jobs.c,v 1.106 2019/03/26 13:32:26 kre Exp $");
+__RCSID("$NetBSD: jobs.c,v 1.107 2020/02/07 02:06:12 kre Exp $");
 #endif
 #endif /* not lint */
 
@@ -820,6 +820,9 @@
                        if ((i = dowait(WBLOCK|WNOFREE, NULL, &job)) == -1)
                               return 128 + lastsig();
 
+                       if (job == NULL)        /* an interloper */
+                               continue;
+
                        /*
                         * one of the job's processes exited,
                         * but there are more



Home | Main Index | Thread Index | Old Index