summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNicholas Marriott <nicm@cvs.openbsd.org>2013-10-10 11:45:30 +0000
committerNicholas Marriott <nicm@cvs.openbsd.org>2013-10-10 11:45:30 +0000
commitd4cac95d82ee39dd9f0ece929d411a52b48a4e8e (patch)
treead11e09237c4ea48459bb0b4acc480ec378eed02
parent49e3f17d4c8dd6ebd9d7e65468ea09e49838da5f (diff)
Pass flags into cmdq_guard as an argument since sometimes cmdq->cmd can
be NULL. Avoids crash when a command in a command client can't be parsed.
-rw-r--r--usr.bin/tmux/cmd-queue.c18
-rw-r--r--usr.bin/tmux/control.c6
-rw-r--r--usr.bin/tmux/tmux.h4
3 files changed, 14 insertions, 14 deletions
diff --git a/usr.bin/tmux/cmd-queue.c b/usr.bin/tmux/cmd-queue.c
index 067aa8ad068..87c5fcfea7d 100644
--- a/usr.bin/tmux/cmd-queue.c
+++ b/usr.bin/tmux/cmd-queue.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: cmd-queue.c,v 1.9 2013/06/23 12:41:54 nicm Exp $ */
+/* $OpenBSD: cmd-queue.c,v 1.10 2013/10/10 11:45:28 nicm Exp $ */
/*
* Copyright (c) 2013 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -154,18 +154,15 @@ cmdq_error(struct cmd_q *cmdq, const char *fmt, ...)
/* Print a guard line. */
int
-cmdq_guard(struct cmd_q *cmdq, const char *guard)
+cmdq_guard(struct cmd_q *cmdq, const char *guard, int flags)
{
struct client *c = cmdq->client;
- int flags;
if (c == NULL)
return 0;
if (!(c->flags & CLIENT_CONTROL))
return 0;
- flags = !!(cmdq->cmd->flags & CMD_CONTROL);
-
evbuffer_add_printf(c->stdout_data, "%%%s %ld %u %d\n", guard,
(long) cmdq->time, cmdq->number, flags);
server_push_stdout(c);
@@ -202,7 +199,7 @@ cmdq_continue(struct cmd_q *cmdq)
{
struct cmd_q_item *next;
enum cmd_retval retval;
- int empty, guard;
+ int empty, guard, flags;
char s[1024];
notify_disable();
@@ -228,13 +225,16 @@ cmdq_continue(struct cmd_q *cmdq)
cmdq->time = time(NULL);
cmdq->number++;
- guard = cmdq_guard(cmdq, "begin");
+ flags = !!(cmdq->cmd->flags & CMD_CONTROL);
+ guard = cmdq_guard(cmdq, "begin", flags);
+
retval = cmdq->cmd->entry->exec(cmdq->cmd, cmdq);
+
if (guard) {
if (retval == CMD_RETURN_ERROR)
- cmdq_guard(cmdq, "error");
+ cmdq_guard(cmdq, "error", flags);
else
- cmdq_guard(cmdq, "end");
+ cmdq_guard(cmdq, "end", flags);
}
if (retval == CMD_RETURN_ERROR)
diff --git a/usr.bin/tmux/control.c b/usr.bin/tmux/control.c
index 5b5543f11c5..f157368b747 100644
--- a/usr.bin/tmux/control.c
+++ b/usr.bin/tmux/control.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: control.c,v 1.11 2013/06/23 12:41:55 nicm Exp $ */
+/* $OpenBSD: control.c,v 1.12 2013/10/10 11:45:29 nicm Exp $ */
/*
* Copyright (c) 2012 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -73,9 +73,9 @@ control_callback(struct client *c, int closed, unused void *data)
c->cmdq->time = time(NULL);
c->cmdq->number++;
- cmdq_guard(c->cmdq, "begin");
+ cmdq_guard(c->cmdq, "begin", 1);
control_write(c, "parse error: %s", cause);
- cmdq_guard(c->cmdq, "error");
+ cmdq_guard(c->cmdq, "error", 1);
free(cause);
} else {
diff --git a/usr.bin/tmux/tmux.h b/usr.bin/tmux/tmux.h
index 581887650e6..7038fc707a3 100644
--- a/usr.bin/tmux/tmux.h
+++ b/usr.bin/tmux/tmux.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: tmux.h,v 1.415 2013/07/05 14:38:23 nicm Exp $ */
+/* $OpenBSD: tmux.h,v 1.416 2013/10/10 11:45:29 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -1871,7 +1871,7 @@ int cmdq_free(struct cmd_q *);
void printflike2 cmdq_print(struct cmd_q *, const char *, ...);
void printflike2 cmdq_info(struct cmd_q *, const char *, ...);
void printflike2 cmdq_error(struct cmd_q *, const char *, ...);
-int cmdq_guard(struct cmd_q *, const char *);
+int cmdq_guard(struct cmd_q *, const char *, int);
void cmdq_run(struct cmd_q *, struct cmd_list *);
void cmdq_append(struct cmd_q *, struct cmd_list *);
int cmdq_continue(struct cmd_q *);