aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTharre <tharre3@gmail.com>2023-04-08 23:23:28 +0200
committerTharre <tharre3@gmail.com>2025-02-05 21:45:38 +0100
commit90c9e2c65bebd9210c417e309cccad03630c60f2 (patch)
tree2d407cbd18ddc75ed53b7526f6b31606d5abfafc
parentda5e2454c0e7ec252c92414b911cb5535052e60c (diff)
downloadst-transparency-90c9e2c65bebd9210c417e309cccad03630c60f2.tar.gz
st-transparency-90c9e2c65bebd9210c417e309cccad03630c60f2.tar.xz
st-transparency-90c9e2c65bebd9210c417e309cccad03630c60f2.zip
Add bracketed paste mode escape sequence filtering
Adapted from a patch by Jann Horn send to the suckless mailing list[0]. An example attack can be found here[1]. [0] https://lists.suckless.org/hackers/1711/15672.html [1] https://thejh.net/misc/website-terminal-copy-paste
-rw-r--r--x.c22
1 files changed, 20 insertions, 2 deletions
diff --git a/x.c b/x.c
index 58616e3..0d86a71 100644
--- a/x.c
+++ b/x.c
@@ -524,7 +524,7 @@ selnotify(XEvent *e)
{
ulong nitems, ofs, rem;
int format;
- uchar *data, *last, *repl;
+ uchar *data, *last, *repl, *readpos;
Atom type, incratom, property = None;
incratom = XInternAtom(xw.dpy, "INCR", 0);
@@ -589,9 +589,27 @@ selnotify(XEvent *e)
*repl++ = '\r';
}
+ /*
+ * In bracketed paste mode, we mark the pasted data by adding
+ * escape sequences around it (see below), but we also want to
+ * prevent the pasted data from prematurely signaling an end
+ * of paste. Therefore, strip escape characters from the
+ * pasted data.
+ */
+ if (IS_SET(MODE_BRCKTPASTE)) {
+ readpos = data;
+ repl = data;
+ while (readpos < last) {
+ if (*readpos != '\033')
+ *repl++ = *readpos;
+ readpos++;
+ }
+ last = repl;
+ }
+
if (IS_SET(MODE_BRCKTPASTE) && ofs == 0)
ttywrite("\033[200~", 6, 0);
- ttywrite((char *)data, nitems * format / 8, 1);
+ ttywrite((char *)data, last - data, 1);
if (IS_SET(MODE_BRCKTPASTE) && rem == 0)
ttywrite("\033[201~", 6, 0);
XFree(data);