sandbox: check if stdin/out is associated with a tty

This commit is contained in:
Bo Anderson 2021-08-24 15:09:25 +01:00
parent aa04277dc2
commit d4c691e91e
No known key found for this signature in database
GPG Key ID: 3DB94E204E137D65

View File

@ -97,15 +97,17 @@ class Sandbox
seatbelt.close
@start = Time.now
$stdin.raw!
$stdin.raw! if $stdin.tty?
stdin_thread = T.let(nil, T.nilable(Thread))
begin
command = [SANDBOX_EXEC, "-f", seatbelt.path, *args]
# Start sandbox in a pseudoterminal to prevent access of the parent terminal.
T.unsafe(PTY).spawn(*command) do |r, w, pid|
w.winsize = $stdout.winsize
trap(:WINCH) { w.winsize = $stdout.winsize }
if $stdout.tty?
w.winsize = $stdout.winsize
trap(:WINCH) { w.winsize = $stdout.winsize }
end
stdin_thread = Thread.new { IO.copy_stream($stdin, w) }
r.each_char { |c| print(c) }
Process.wait(pid)
@ -116,7 +118,7 @@ class Sandbox
raise
ensure
stdin_thread&.kill
$stdin.cooked!
$stdin.cooked! if $stdin.tty?
seatbelt.unlink
sleep 0.1 # wait for a bit to let syslog catch up the latest events.