diff options
author | Nicholas Marriott <nicholas.marriott@gmail.com> | 2009-07-02 16:23:54 +0000 |
---|---|---|
committer | Nicholas Marriott <nicholas.marriott@gmail.com> | 2009-07-02 16:23:54 +0000 |
commit | 29ac832cb38f2193866a3fa5b14abc7537852eb4 (patch) | |
tree | 862827f88fa3204e0e8bc24d8a50b0b5cfe327de | |
parent | 85dac1e378ed398ff5f6fd861b9874ec2f9ad2f5 (diff) |
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.
-rw-r--r-- | cmd-paste-buffer.c | 4 | ||||
-rw-r--r-- | paste.c | 5 | ||||
-rw-r--r-- | window-copy.c | 4 |
3 files changed, 8 insertions, 5 deletions
diff --git a/cmd-paste-buffer.c b/cmd-paste-buffer.c index 2598b39d..2baf94ab 100644 --- a/cmd-paste-buffer.c +++ b/cmd-paste-buffer.c @@ -1,4 +1,4 @@ -/* $Id: cmd-paste-buffer.c,v 1.15 2009-01-19 18:23:40 nicm Exp $ */ +/* $Id: cmd-paste-buffer.c,v 1.16 2009-07-02 16:23:54 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net> @@ -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. */ @@ -1,4 +1,4 @@ -/* $Id: paste.c,v 1.6 2009-01-25 18:51:28 tcunha Exp $ */ +/* $Id: paste.c,v 1.7 2009-07-02 16:23:54 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net> @@ -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 f25ef22b..71d4459c 100644 --- a/window-copy.c +++ b/window-copy.c @@ -1,4 +1,4 @@ -/* $Id: window-copy.c,v 1.60 2009-05-04 17:58:27 nicm Exp $ */ +/* $Id: window-copy.c,v 1.61 2009-07-02 16:23:54 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net> @@ -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 { |