ash,hush: ">&10" redirects to script/tty fds should not work
authorDenys Vlasenko <vda.linux@googlemail.com>
Mon, 31 Jul 2017 02:32:06 +0000 (04:32 +0200)
committerDenys Vlasenko <vda.linux@googlemail.com>
Mon, 31 Jul 2017 02:35:18 +0000 (04:35 +0200)
commit32fdf2f9fc9a617918672d71579f4ad42eb9bde9
treef73fbaa257aeb6810557fe7a36ae6b4b3dfb72e4
parent035486c7500c09616a6c1040d8e70923532a5c2d
ash,hush: ">&10" redirects to script/tty fds should not work

The fact that shell has open fds to tty and/or scripts should be
unobservable, if possible. In particular, if redirect tries to dup
one of them via ">&script_fd", it's better to pretend that script_fd
is closed, and thus redirect fails with EBADF.

Fixes these two testcase failures:
ash-redir/redir_to_bad_fd.tests
hush-redir/redir_to_bad_fd3.tests

function                                             old     new   delta
redirect                                            1018    1129    +111
setup_redirects                                      250     359    +109
readtoken1                                          2651    2655      +4
cmdloop                                              185     187      +2
changepath                                           194     195      +1
save_fd_on_redirect                                  203     194      -9
evaltree                                             501     484     -17
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 5/2 up/down: 227/-26)           Total: 201 bytes
   text    data     bss     dec     hex filename
 914553     485    6848  921886   e111e busybox_old
 914754     485    6848  922087   e11e7 busybox_unstripped

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
shell/ash.c
shell/hush.c