hush: fix fallout from FILE->HFILE conversion
authorDenys Vlasenko <vda.linux@googlemail.com>
Sun, 5 Aug 2018 12:55:01 +0000 (14:55 +0200)
committerDenys Vlasenko <vda.linux@googlemail.com>
Sun, 5 Aug 2018 16:11:15 +0000 (18:11 +0200)
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
shell/hush.c

index 3407711cdd282a04df737b830f20470a25e7abbe..c4b1248259f10a6b64f83b94a40bd966be98c94e 100644 (file)
@@ -1683,9 +1683,15 @@ static void close_all_HFILE_list(void)
                 * It is disastrous if we share memory with a vforked parent.
                 * I'm not sure we never come here after vfork.
                 * Therefore just close fd, nothing more.
+                *
+                * ">" instead of ">=": we don't close fd#0,
+                * interactive shell uses hfopen(NULL) as stdin input
+                * which has fl->fd == 0, but fd#0 gets redirected in pipes.
+                * If we'd close it here, then e.g. interactive "set | sort"
+                * with NOFORKed sort, would have sort's input fd closed.
                 */
-               /*hfclose(fl); - unsafe */
-               if (fl->fd >= 0)
+               if (fl->fd > 0)
+                       /*hfclose(fl); - unsafe */
                        close(fl->fd);
                fl = fl->next_hfile;
        }