Skip to content

Commit

Permalink
systemd: Use binary channel for Terminal
Browse files Browse the repository at this point in the history
Terminals are not defined/required to be UTF-8 only. Sometimes people
cat binary data to the terminal, or possibly files in other encodings.
These cannot be sent through `TEXT` websocket channels, and will also
trigger the additional checks from commit 1b15dcb.

Use a binary channel to avoid all that. XTerm.js gets along with this
just fine, and it ignores invalid data.

With this you can now even `cat /bin/true` and get something moderately
sensible, instead of no output at all.

Fixes #20791
  • Loading branch information
martinpitt committed Aug 5, 2024
1 parent e57df1e commit 663afa7
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
3 changes: 2 additions & 1 deletion pkg/systemd/terminal.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ const _ = cockpit.gettext;
"TERM=xterm-256color",
],
directory: user.home || "/",
pty: true
pty: true,
binary: true,
});
}

Expand Down
7 changes: 7 additions & 0 deletions test/verify/check-system-terminal
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,13 @@ PROMPT_COMMAND='printf "\033]0;%s@%s:%s\007" "${USER}" "${HOSTNAME%%.*}" "${PWD/

b.input_text('echo -e "1\\u0041"\n')
wait_line(n + 3, '1A')
wait_line(n + 4, prompt)

# non-UTF8 data
m.execute(r"echo -e 'hello\xFF\x01\xFF\x02world' > " + self.vm_tmpdir + "/garbage.txt")
b.input_text(f'cat {self.vm_tmpdir}/garbage.txt\n')
wait_line(n + 5, 'helloworld')
wait_line(n + 6, prompt)

# The '@' sign is in the default prompt
b.wait_in_text(".terminal-title", '@')
Expand Down

0 comments on commit 663afa7

Please sign in to comment.