summaryrefslogtreecommitdiff
path: root/usr.bin/tmux
diff options
context:
space:
mode:
authorNicholas Marriott <nicm@cvs.openbsd.org>2019-10-03 10:39:09 +0000
committerNicholas Marriott <nicm@cvs.openbsd.org>2019-10-03 10:39:09 +0000
commita254e312a1f9a6d61e4ed80989c3b1edcd9448a2 (patch)
treed0d61b51161bdb1a33d15be016929d04d8ebd53d /usr.bin/tmux
parentc1fd52d588d8b580e802e585365f8798ff83b1f3 (diff)
Use a malloc'd buffer for lsk since commands can be very long, from Gregory Pakosz.
Diffstat (limited to 'usr.bin/tmux')
-rw-r--r--usr.bin/tmux/cmd-list-keys.c37
1 files changed, 29 insertions, 8 deletions
diff --git a/usr.bin/tmux/cmd-list-keys.c b/usr.bin/tmux/cmd-list-keys.c
index b31ca97ef82..014a2a0cf13 100644
--- a/usr.bin/tmux/cmd-list-keys.c
+++ b/usr.bin/tmux/cmd-list-keys.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: cmd-list-keys.c,v 1.47 2019/10/03 10:24:05 nicm Exp $ */
+/* $OpenBSD: cmd-list-keys.c,v 1.48 2019/10/03 10:39:08 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com>
@@ -61,8 +61,9 @@ cmd_list_keys_exec(struct cmd *self, struct cmdq_item *item)
struct key_table *table;
struct key_binding *bd;
const char *tablename, *r;
- char *key, *cp, tmp[8192];
+ char *key, *cp, *tmp;
int repeat, width, tablewidth, keywidth;
+ size_t tmpsize, tmpused, cplen;
if (self->entry == &cmd_list_commands_entry)
return (cmd_list_keys_commands(self, item));
@@ -101,6 +102,9 @@ cmd_list_keys_exec(struct cmd *self, struct cmdq_item *item)
table = key_bindings_next_table(table);
}
+ tmpsize = 256;
+ tmp = xmalloc(tmpsize);
+
table = key_bindings_first_table ();
while (table != NULL) {
if (tablename != NULL && strcmp(table->name, tablename) != 0) {
@@ -117,20 +121,35 @@ cmd_list_keys_exec(struct cmd *self, struct cmdq_item *item)
r = "-r ";
else
r = " ";
- xsnprintf(tmp, sizeof tmp, "%s-T ", r);
+ tmpused = xsnprintf(tmp, tmpsize, "%s-T ", r);
cp = utf8_padcstr(table->name, tablewidth);
- strlcat(tmp, cp, sizeof tmp);
- strlcat(tmp, " ", sizeof tmp);
+ cplen = strlen(cp) + 1;
+ while (tmpused + cplen + 1>= tmpsize) {
+ tmpsize *= 2;
+ tmp = xrealloc(tmp, tmpsize);
+ }
+ tmpused = strlcat(tmp, cp, tmpsize);
+ tmpused = strlcat(tmp, " ", tmpsize);
free(cp);
cp = utf8_padcstr(key, keywidth);
- strlcat(tmp, cp, sizeof tmp);
- strlcat(tmp, " ", sizeof tmp);
+ cplen = strlen(cp) + 1;
+ while (tmpused + cplen + 1 >= tmpsize) {
+ tmpsize *= 2;
+ tmp = xrealloc(tmp, tmpsize);
+ }
+ tmpused = strlcat(tmp, cp, tmpsize);
+ tmpused = strlcat(tmp, " ", tmpsize);
free(cp);
cp = cmd_list_print(bd->cmdlist, 1);
- strlcat(tmp, cp, sizeof tmp);
+ cplen = strlen(cp);
+ while (tmpused + cplen + 1 >= tmpsize) {
+ tmpsize *= 2;
+ tmp = xrealloc(tmp, tmpsize);
+ }
+ strlcat(tmp, cp, tmpsize);
free(cp);
cmdq_print(item, "bind-key %s", tmp);
@@ -141,6 +160,8 @@ cmd_list_keys_exec(struct cmd *self, struct cmdq_item *item)
table = key_bindings_next_table(table);
}
+ free(tmp);
+
return (CMD_RETURN_NORMAL);
}