summaryrefslogtreecommitdiffstats
path: root/usr.bin/tmux/cmd-list-keys.c
diff options
context:
space:
mode:
authornicm <nicm@openbsd.org>2019-10-03 10:39:08 +0000
committernicm <nicm@openbsd.org>2019-10-03 10:39:08 +0000
commit7da19389bdc341a31caf3d917f0518d0a5f079cc (patch)
treede1028205779e8bcaf24aad260046c98a79b637c /usr.bin/tmux/cmd-list-keys.c
parentremove device_tree_address from rpi config.txt (diff)
downloadwireguard-openbsd-7da19389bdc341a31caf3d917f0518d0a5f079cc.tar.xz
wireguard-openbsd-7da19389bdc341a31caf3d917f0518d0a5f079cc.zip
Use a malloc'd buffer for lsk since commands can be very long, from Gregory Pakosz.
Diffstat (limited to 'usr.bin/tmux/cmd-list-keys.c')
-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);
}