From: nicm Date: Thu, 9 Jun 2022 09:12:55 +0000 (+0000) Subject: If an application gives the first parameter to OSC 52, validate and pass X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=1b09dd8dc5554c251f9b84fdc4ebaffda3dc4ea0;p=openbsd If an application gives the first parameter to OSC 52, validate and pass on to outside terminal. GitHub issue 3192. --- diff --git a/usr.bin/tmux/cmd-load-buffer.c b/usr.bin/tmux/cmd-load-buffer.c index 43d538c59d8..bca634352f8 100644 --- a/usr.bin/tmux/cmd-load-buffer.c +++ b/usr.bin/tmux/cmd-load-buffer.c @@ -1,4 +1,4 @@ -/* $OpenBSD: cmd-load-buffer.c,v 1.64 2021/08/21 10:22:39 nicm Exp $ */ +/* $OpenBSD: cmd-load-buffer.c,v 1.65 2022/06/09 09:12:55 nicm Exp $ */ /* * Copyright (c) 2009 Tiago Cunha @@ -77,7 +77,7 @@ cmd_load_buffer_done(__unused struct client *c, const char *path, int error, } else if (tc != NULL && tc->session != NULL && (~tc->flags & CLIENT_DEAD)) - tty_set_selection(&tc->tty, copy, bsize); + tty_set_selection(&tc->tty, "", copy, bsize); if (tc != NULL) server_client_unref(tc); } diff --git a/usr.bin/tmux/cmd-set-buffer.c b/usr.bin/tmux/cmd-set-buffer.c index e6e10a871ae..52118ce9e93 100644 --- a/usr.bin/tmux/cmd-set-buffer.c +++ b/usr.bin/tmux/cmd-set-buffer.c @@ -1,4 +1,4 @@ -/* $OpenBSD: cmd-set-buffer.c,v 1.33 2022/06/02 20:41:21 nicm Exp $ */ +/* $OpenBSD: cmd-set-buffer.c,v 1.34 2022/06/09 09:12:55 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott @@ -131,7 +131,7 @@ cmd_set_buffer_exec(struct cmd *self, struct cmdq_item *item) return (CMD_RETURN_ERROR); } if (args_has(args, 'w') && tc != NULL) - tty_set_selection(&tc->tty, bufdata, bufsize); + tty_set_selection(&tc->tty, "", bufdata, bufsize); return (CMD_RETURN_NORMAL); } diff --git a/usr.bin/tmux/input.c b/usr.bin/tmux/input.c index 0724c8f307f..202d9e57aa8 100644 --- a/usr.bin/tmux/input.c +++ b/usr.bin/tmux/input.c @@ -1,4 +1,4 @@ -/* $OpenBSD: input.c,v 1.202 2022/05/30 13:00:18 nicm Exp $ */ +/* $OpenBSD: input.c,v 1.203 2022/06/09 09:12:55 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott @@ -2693,6 +2693,9 @@ input_osc_52(struct input_ctx *ictx, const char *p) int outlen, state; struct screen_write_ctx ctx; struct paste_buffer *pb; + const char* allow = "cpqs01234567"; + char flags[sizeof allow] = ""; + u_int i, j = 0; if (wp == NULL) return; @@ -2707,6 +2710,12 @@ input_osc_52(struct input_ctx *ictx, const char *p) return; log_debug("%s: %s", __func__, end); + for (i = 0; p + i != end; i++) { + if (strchr(allow, p[i]) != NULL && strchr(flags, p[i]) == NULL) + flags[j++] = p[i]; + } + log_debug("%s: %.*s %s", __func__, (int)(end - p - 1), p, flags); + if (strcmp(end, "?") == 0) { if ((pb = paste_get_top(NULL)) != NULL) buf = paste_buffer_data(pb, &len); @@ -2728,7 +2737,7 @@ input_osc_52(struct input_ctx *ictx, const char *p) } screen_write_start_pane(&ctx, wp, NULL); - screen_write_setselection(&ctx, out, outlen); + screen_write_setselection(&ctx, flags, out, outlen); screen_write_stop(&ctx); notify_pane("pane-set-clipboard", wp); diff --git a/usr.bin/tmux/screen-write.c b/usr.bin/tmux/screen-write.c index 6339a9e5c39..814a1bff4d7 100644 --- a/usr.bin/tmux/screen-write.c +++ b/usr.bin/tmux/screen-write.c @@ -1,4 +1,4 @@ -/* $OpenBSD: screen-write.c,v 1.207 2022/03/17 13:39:13 nicm Exp $ */ +/* $OpenBSD: screen-write.c,v 1.208 2022/06/09 09:12:55 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott @@ -2085,12 +2085,14 @@ screen_write_overwrite(struct screen_write_ctx *ctx, struct grid_cell *gc, /* Set external clipboard. */ void -screen_write_setselection(struct screen_write_ctx *ctx, u_char *str, u_int len) +screen_write_setselection(struct screen_write_ctx *ctx, const char *flags, + u_char *str, u_int len) { struct tty_ctx ttyctx; screen_write_initctx(ctx, &ttyctx, 0); ttyctx.ptr = str; + ttyctx.ptr2 = (void *)flags; ttyctx.num = len; tty_write(tty_cmd_setselection, &ttyctx); diff --git a/usr.bin/tmux/tmux.h b/usr.bin/tmux/tmux.h index b6d495a4bad..46bfd0cb8c3 100644 --- a/usr.bin/tmux/tmux.h +++ b/usr.bin/tmux/tmux.h @@ -1,4 +1,4 @@ -/* $OpenBSD: tmux.h,v 1.1172 2022/06/07 10:02:19 nicm Exp $ */ +/* $OpenBSD: tmux.h,v 1.1173 2022/06/09 09:12:55 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott @@ -1421,6 +1421,7 @@ struct tty_ctx { u_int num; void *ptr; + void *ptr2; /* * Cursor and region position before the screen was updated - this is @@ -2278,7 +2279,7 @@ int tty_open(struct tty *, char **); void tty_close(struct tty *); void tty_free(struct tty *); void tty_update_features(struct tty *); -void tty_set_selection(struct tty *, const char *, size_t); +void tty_set_selection(struct tty *, const char *, const char *, size_t); void tty_write(void (*)(struct tty *, const struct tty_ctx *), struct tty_ctx *); void tty_cmd_alignmenttest(struct tty *, const struct tty_ctx *); @@ -2872,7 +2873,8 @@ void screen_write_collect_end(struct screen_write_ctx *); void screen_write_collect_add(struct screen_write_ctx *, const struct grid_cell *); void screen_write_cell(struct screen_write_ctx *, const struct grid_cell *); -void screen_write_setselection(struct screen_write_ctx *, u_char *, u_int); +void screen_write_setselection(struct screen_write_ctx *, const char *, + u_char *, u_int); void screen_write_rawstring(struct screen_write_ctx *, u_char *, u_int); void screen_write_alternateon(struct screen_write_ctx *, struct grid_cell *, int); diff --git a/usr.bin/tmux/tty.c b/usr.bin/tmux/tty.c index 38305383d46..a36d843f0de 100644 --- a/usr.bin/tmux/tty.c +++ b/usr.bin/tmux/tty.c @@ -1,4 +1,4 @@ -/* $OpenBSD: tty.c,v 1.419 2022/06/03 08:09:16 nicm Exp $ */ +/* $OpenBSD: tty.c,v 1.420 2022/06/09 09:12:55 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott @@ -671,7 +671,7 @@ static void tty_force_cursor_colour(struct tty *tty, int c) { u_char r, g, b; - char s[13] = ""; + char s[13]; if (c != -1) c = colour_force_rgb(c); @@ -2082,11 +2082,12 @@ tty_cmd_cells(struct tty *tty, const struct tty_ctx *ctx) void tty_cmd_setselection(struct tty *tty, const struct tty_ctx *ctx) { - tty_set_selection(tty, ctx->ptr, ctx->num); + tty_set_selection(tty, ctx->ptr2, ctx->ptr, ctx->num); } void -tty_set_selection(struct tty *tty, const char *buf, size_t len) +tty_set_selection(struct tty *tty, const char *flags, const char *buf, + size_t len) { char *encoded; size_t size; @@ -2101,7 +2102,7 @@ tty_set_selection(struct tty *tty, const char *buf, size_t len) b64_ntop(buf, len, encoded, size); tty->flags |= TTY_NOBLOCK; - tty_putcode_ptr2(tty, TTYC_MS, "", encoded); + tty_putcode_ptr2(tty, TTYC_MS, flags, encoded); free(encoded); } diff --git a/usr.bin/tmux/window-copy.c b/usr.bin/tmux/window-copy.c index 63511f84c4a..a6a02ab5217 100644 --- a/usr.bin/tmux/window-copy.c +++ b/usr.bin/tmux/window-copy.c @@ -1,4 +1,4 @@ -/* $OpenBSD: window-copy.c,v 1.334 2022/05/30 13:00:19 nicm Exp $ */ +/* $OpenBSD: window-copy.c,v 1.335 2022/06/09 09:12:55 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott @@ -4570,7 +4570,7 @@ window_copy_copy_buffer(struct window_mode_entry *wme, const char *prefix, if (options_get_number(global_options, "set-clipboard") != 0) { screen_write_start_pane(&ctx, wp, NULL); - screen_write_setselection(&ctx, buf, len); + screen_write_setselection(&ctx, "", buf, len); screen_write_stop(&ctx); notify_pane("pane-set-clipboard", wp); } @@ -4644,7 +4644,7 @@ window_copy_append_selection(struct window_mode_entry *wme) if (options_get_number(global_options, "set-clipboard") != 0) { screen_write_start_pane(&ctx, wp, NULL); - screen_write_setselection(&ctx, buf, len); + screen_write_setselection(&ctx, "", buf, len); screen_write_stop(&ctx); notify_pane("pane-set-clipboard", wp); }