On Sun 22 Jan 2023 at 03:50:17 (+0100), Vincent Lefevre wrote:
> The following issue is reproducible in several terminals, e.g. xterm
> and GNOME Terminal, and several shells, e.g. bash and zsh.
> 
> 1. From the shell in an X terminal emulator, run an X application
> in foreground, e.g. emacs-gtk or xterm.
> 
> 2. Paste a long text (e.g. the contents of /usr/share/doc/libc6/copyright
> to choose an example every one has) in the terminal. Actually, only
> the beginning of the text appears in the terminal.

Well, strictly, I see the end of the first portion of the pasted file.
The input buffer of xterm fills up, ironically at "Por" in one of the
lines containing "Portions Copyright … …". The beginning of the file
/usr/share/doc/libc6/copyright has scrolled off the top by then.

> 3. Type Ctrl-C (one or several times) in the terminal.
> But nothing happens.

I presume that's because the input buffer is already full, so
you'd need what I think they called an out-of-band signal,
like pressing Break used to do on an old teletype terminal.

> 4. Quit the X application that was started at step 1.
> 
> Result: many lines of the pasted text are executed by the shell!
> 
> This issue doesn't occur when the pasted text is short: the Ctrl-C
> kills the X application via a SIGINT and nothing is executed.

Yes, because in this case, ^C makes it into the input to xterm.

> You may wonder why one would paste a long text at step 2. In fact,
> this happens by accident: I sometimes paste data in the terminal
> instead of the application (typically Emacs). And this is really
> annoying, in particular when lines contains the ">" character,
> which has the effect to create files.
> 
> Is there any way to avoid this issue?

Make sure that the application's data is saved, eg, ^X^S in emacs,
but don't exit the application, eg, ^X^C in emacs.

Then click on the X that closes the xterm window, which takes
down both xterm and the application with it. This is effectively
an out-of-band signal.

Finally, open another xterm with your WM's menu, to replace it.

Cheers,
David.

Reply via email to