sites

public wiki contents of suckless.org
git clone git://git.suckless.org/sites
Log | Files | Refs

commit d1fb8337a5ce388866d55d4b11e821952de188a7
parent 73228dbb9489e9f9a8bb6ba41f83bc6430cd8d6a
Author: Andrew Mass <amass1212@gmail.com>
Date:   Sat, 17 May 2025 15:53:56 +0100

[st][patches][paste_controls] Added patch.

Diffstat:
Ast.suckless.org/patches/paste_controls/index.md | 18++++++++++++++++++
Ast.suckless.org/patches/paste_controls/st-paste_controls-0.9.2.diff | 40++++++++++++++++++++++++++++++++++++++++
2 files changed, 58 insertions(+), 0 deletions(-)

diff --git a/st.suckless.org/patches/paste_controls/index.md b/st.suckless.org/patches/paste_controls/index.md @@ -0,0 +1,18 @@ +paste\_controls +=============== + +Description +----------- +Replaces most [C0 control codes](https://www.ascii-code.com/characters/control-characters) +with spaces when pasting, except for HT and CR. + +This can add some security when pasting untrusted buffers, for example +[commands from a browser](https://thejh.net/misc/website-terminal-copy-paste). + +Download +-------- +* [st-paste\_controls-0.9.2.diff](st-paste_controls-0.9.2.diff) + +Author +------ +* Andrew Mass - <amass1212@gmail.com> diff --git a/st.suckless.org/patches/paste_controls/st-paste_controls-0.9.2.diff b/st.suckless.org/patches/paste_controls/st-paste_controls-0.9.2.diff @@ -0,0 +1,40 @@ +diff --git a/x.c b/x.c +index bd23686..254d3d0 100644 +--- a/x.c ++++ b/x.c +@@ -580,11 +580,33 @@ selnotify(XEvent *e) + * copy and pasting. When receiving some selection data, + * replace all '\n' with '\r'. + * FIXME: Fix the computer world. ++ * ++ * Also, replace most C0 control codes with spaces, except for ++ * HT and CR. Note that we are not replacing C1 control codes ++ * (0x80 to 0x9F), as these are possibly valid UTF-8 ++ * continuation bytes. + */ + repl = data; + last = data + nitems * format / 8; +- while ((repl = memchr(repl, '\n', last - repl))) { +- *repl++ = '\r'; ++ while (repl != last) { ++ if (*repl <= 0x1f) { ++ switch (*repl) { ++ case 0x09: /* HT \t */ ++ case 0x0D: /* CR \r */ ++ repl++; ++ break; ++ case 0x0a: /* LF \n */ ++ *repl++ = '\r'; ++ break; ++ default: ++ *repl++ = ' '; ++ break; ++ }; ++ } else if (*repl == 0x7f) { /* DEL */ ++ *repl++ = ' '; ++ } else { ++ repl++; ++ } + } + + if (IS_SET(MODE_BRCKTPASTE) && ofs == 0)