Skip to content

Commit

Permalink
Make maximum clipboard buffer lenght configurable
Browse files Browse the repository at this point in the history
  • Loading branch information
alimirjamali committed Oct 6, 2024
1 parent 9966538 commit b0cb18f
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 4 deletions.
5 changes: 5 additions & 0 deletions gui-daemon/guid.conf
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
23 changes: 19 additions & 4 deletions gui-daemon/xside.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
}
Expand Down
6 changes: 6 additions & 0 deletions gui-daemon/xside.h
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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) */
Expand Down

0 comments on commit b0cb18f

Please sign in to comment.