From fe5edad1fcd60d94bc45ca49f94636eeecae210d Mon Sep 17 00:00:00 2001 From: Nicholas Marriott Date: Thu, 2 Jul 2009 16:15:43 +0000 Subject: [PATCH] Fix two copy/paste bugs: forbid zero-length buffers to prevent a fatal error when trying to paste them, found by me, and miscalculation of the start/end causing random fatal errors when copying in copy-mode, reported by sthen. ok sthen "put it in" deraadt --- cmd-paste-buffer.c | 2 +- paste.c | 3 +++ window-copy.c | 2 +- 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/cmd-paste-buffer.c b/cmd-paste-buffer.c index 35472d3d..3f4cfe2e 100644 --- a/cmd-paste-buffer.c +++ b/cmd-paste-buffer.c @@ -63,7 +63,7 @@ cmd_paste_buffer_exec(struct cmd *self, struct cmd_ctx *ctx) } } - if (pb != NULL) + if (pb != NULL && *pb->data != '\0') buffer_write(w->active->out, pb->data, strlen(pb->data)); /* Delete the buffer if -d. */ diff --git a/paste.c b/paste.c index 3644381c..981385e9 100644 --- a/paste.c +++ b/paste.c @@ -101,6 +101,9 @@ paste_add(struct paste_stack *ps, char *data, u_int limit) { struct paste_buffer *pb; + if (*data == '\0') + return; + while (ARRAY_LENGTH(ps) >= limit) ARRAY_TRUNC(ps, 1); diff --git a/window-copy.c b/window-copy.c index dc2a4d45..a64be760 100644 --- a/window-copy.c +++ b/window-copy.c @@ -423,7 +423,7 @@ window_copy_copy_selection(struct window_pane *wp, struct client *c) /* Find start and end. */ xx = data->cx + data->ox; yy = screen_hsize(&wp->base) + data->cy - data->oy; - if (xx < data->selx || (yy == data->sely && xx < data->selx)) { + if (yy < data->sely || (yy == data->sely && xx < data->selx)) { sx = xx; sy = yy; ex = data->selx; ey = data->sely; } else {