From b0cb18f43f577b8985d552ea706bce800d29d466 Mon Sep 17 00:00:00 2001 From: Ali Mirjamali Date: Sun, 6 Oct 2024 13:25:30 +0330 Subject: [PATCH] Make maximum clipboard buffer lenght configurable fixes: https://github.com/QubesOS/qubes-issues/issues/9296 --- gui-daemon/guid.conf | 5 +++++ gui-daemon/xside.c | 23 +++++++++++++++++++---- gui-daemon/xside.h | 6 ++++++ 3 files changed, 30 insertions(+), 4 deletions(-) diff --git a/gui-daemon/guid.conf b/gui-daemon/guid.conf index 3f1530a..915e62f 100644 --- a/gui-daemon/guid.conf +++ b/gui-daemon/guid.conf @@ -80,4 +80,9 @@ global: { # Timeout when waiting for qubes-gui-agent # # startup_timeout = 45; + + # Inter-qube clipboard maximum character limit. This could be between 32000 to + # 16000000 characters. Default is 256000 characters. + # + # max_clipboard_size = 256000 } diff --git a/gui-daemon/xside.c b/gui-daemon/xside.c index 947596c..ad235df 100644 --- a/gui-daemon/xside.c +++ b/gui-daemon/xside.c @@ -939,8 +939,8 @@ static int run_clipboard_rpc(Ghandles * g, enum clipboard_op op) { } umask(old_umask); if (op == CLIPBOARD_COPY) { - rl.rlim_cur = MAX_CLIPBOARD_SIZE; - rl.rlim_max = MAX_CLIPBOARD_SIZE; + rl.rlim_cur = g->clipboard_buffer_size; + rl.rlim_max = g->clipboard_buffer_size; setrlimit(RLIMIT_FSIZE, &rl); } dup2(fd, 1); @@ -1019,7 +1019,7 @@ static void handle_clipboard_data(Ghandles * g, unsigned int untrusted_len) if (g->log_level > 0) fprintf(stderr, "handle_clipboard_data, len=0x%x\n", untrusted_len); - if (untrusted_len > MAX_CLIPBOARD_SIZE) { + if (untrusted_len > g->clipboard_buffer_size) { fprintf(stderr, "clipboard data len 0x%x?\n", untrusted_len); exit(1); @@ -4119,6 +4119,7 @@ static void load_default_config_values(Ghandles * g) g->copy_seq_key = XK_c; g->paste_seq_mask = ControlMask | ShiftMask; g->paste_seq_key = XK_v; + g->clipboard_buffer_size = DEFAULT_CLIPBOARD_BUFFER_SIZE; g->allow_fullscreen = 0; g->override_redirect_protection = 1; g->startup_timeout = 45; @@ -4190,6 +4191,20 @@ static void parse_vm_config(Ghandles * g, config_setting_t * group) &g->paste_seq_mask, &g->paste_seq_key); } + if ((setting = + config_setting_get_member(group, "max_clipboard_size"))) { + int value = config_setting_get_int(setting); + if (value > MAX_CLIPBOARD_BUFFER_SIZE || value < MIN_CLIPBOARD_BUFFER_SIZE) { + fprintf(stderr, + "unsupported value ‘%d’ for max_clipboard_size " + "(must be between %d to %d characters.\n", + value, MAX_CLIPBOARD_BUFFER_SIZE, MIN_CLIPBOARD_BUFFER_SIZE); + exit(1); + } else { + g->clipboard_buffer_size = value; + } + } + if ((setting = config_setting_get_member(group, "allow_utf8_titles"))) { g->allow_utf8_titles = config_setting_get_bool(setting); @@ -4237,7 +4252,7 @@ static void parse_vm_config(Ghandles * g, config_setting_t * group) g->disable_override_redirect = 0; else { fprintf(stderr, - "unsupported value ‘%s’ for override_redirect (must be ‘disabled’ or ‘allow’\n", + "unsupported value ‘%s’ for override_redirect (must be ‘disabled’ or ‘allow’)\n", value); exit(1); } diff --git a/gui-daemon/xside.h b/gui-daemon/xside.h index f799c86..a25a614 100644 --- a/gui-daemon/xside.h +++ b/gui-daemon/xside.h @@ -51,6 +51,11 @@ #define QUBES_SERVICE_EVAL_SIMPLE "policy.EvalSimple" #define QUBES_SERVICE_EVAL_GUI "policy.EvalGUI" +/* default, minimum and maximum clipboard buffer lenght */ +#define DEFAULT_CLIPBOARD_BUFFER_SIZE = 256000 +#define MIN_CLIPBOARD_BUFFER_SIZE = 32000 +#define MAX_CLIPBOARD_BUFFER_SIZE = 16000000 + /* default width of forced colorful border */ #define BORDER_WIDTH 2 @@ -218,6 +223,7 @@ struct _global_handles { KeySym copy_seq_key; /* key for secure-copy key sequence */ int paste_seq_mask; /* modifiers mask for secure-paste key sequence */ KeySym paste_seq_key; /* key for secure-paste key sequence */ + int clipboard_buffer_size; /* maximum clipboard character limit */ int qrexec_clipboard; /* 0: use GUI protocol to fetch/put clipboard, 1: use qrexec */ int use_kdialog; /* use kdialog for prompts (default on KDE) or zenity (default on non-KDE) */ int prefix_titles; /* prefix windows titles with VM name (for WM without support for _QUBES_VMNAME property) */