diff options
author | Nicholas Marriott <nicm@cvs.openbsd.org> | 2020-06-11 10:56:20 +0000 |
---|---|---|
committer | Nicholas Marriott <nicm@cvs.openbsd.org> | 2020-06-11 10:56:20 +0000 |
commit | 49a6d9d8c94a9e45ebc01e049ca416f525559da9 (patch) | |
tree | eb5aa8e29b2cc7e48bf3fa3338b8eae167d237ac /usr.bin/tmux/status.c | |
parent | 5cac799121f5895596fe597420633edb59d403d2 (diff) |
Fix a crash when completing sessions, from Anindya Mukherjee.
Diffstat (limited to 'usr.bin/tmux/status.c')
-rw-r--r-- | usr.bin/tmux/status.c | 25 |
1 files changed, 18 insertions, 7 deletions
diff --git a/usr.bin/tmux/status.c b/usr.bin/tmux/status.c index adba1dfb9f5..f1e7a929df4 100644 --- a/usr.bin/tmux/status.c +++ b/usr.bin/tmux/status.c @@ -1,4 +1,4 @@ -/* $OpenBSD: status.c,v 1.216 2020/05/26 08:56:48 nicm Exp $ */ +/* $OpenBSD: status.c,v 1.217 2020/06/11 10:56:19 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com> @@ -1441,6 +1441,8 @@ status_prompt_complete_prefix(char **list, u_int size) u_int i; size_t j; + if (list == NULL || size == 0) + return (NULL); out = xstrdup(list[0]); for (i = 1; i < size; i++) { j = strlen(list[i]); @@ -1649,13 +1651,22 @@ status_prompt_complete_session(char ***list, u_int *size, const char *s, char flag) { struct session *loop; - char *out, *tmp; + char *out, *tmp, n[11]; RB_FOREACH(loop, sessions, &sessions) { - if (*s != '\0' && strncmp(loop->name, s, strlen(s)) != 0) - continue; - *list = xreallocarray(*list, (*size) + 2, sizeof **list); - xasprintf(&(*list)[(*size)++], "%s:", loop->name); + if (*s == '\0' || strncmp(loop->name, s, strlen(s)) == 0) { + *list = xreallocarray(*list, (*size) + 2, + sizeof **list); + xasprintf(&(*list)[(*size)++], "%s:", loop->name); + } else if (*s == '$') { + xsnprintf(n, sizeof n, "%u", loop->id); + if (s[1] == '\0' || + strncmp(n, s + 1, strlen(s) - 1) == 0) { + *list = xreallocarray(*list, (*size) + 2, + sizeof **list); + xasprintf(&(*list)[(*size)++], "$%s:", n); + } + } } out = status_prompt_complete_prefix(*list, *size); if (out != NULL && flag != '\0') { @@ -1670,7 +1681,7 @@ status_prompt_complete_session(char ***list, u_int *size, const char *s, static char * status_prompt_complete(struct client *c, const char *word, u_int offset) { - struct session *session; + struct session *session; const char *s, *colon; char **list = NULL, *copy = NULL, *out = NULL; char flag = '\0'; |