From dd41035a4d71057108da8c7b5e1876cc02b4995c Mon Sep 17 00:00:00 2001 From: Nicholas Marriott Date: Tue, 1 Jul 2008 19:47:02 +0000 Subject: [PATCH] Protocol versioning, version is checked on identify message. --- CHANGES | 4 +++- client.c | 3 ++- server-msg.c | 12 ++++++++++-- tmux.h | 7 +++++-- 4 files changed, 20 insertions(+), 6 deletions(-) diff --git a/CHANGES b/CHANGES index 3eae1e03..20f08576 100644 --- a/CHANGES +++ b/CHANGES @@ -1,5 +1,7 @@ 01 July 2008 +* Protocol versioning. Clients which identify as a different version from the + server will be rejected. * tmux 0.4 released. 29 June 2008 @@ -596,4 +598,4 @@ (including mutt, emacs). No status bar yet and no key remapping or other customisation. -$Id: CHANGES,v 1.147 2008-07-01 05:43:00 nicm Exp $ +$Id: CHANGES,v 1.148 2008-07-01 19:47:02 nicm Exp $ diff --git a/client.c b/client.c index 308c1067..a55b8e22 100644 --- a/client.c +++ b/client.c @@ -1,4 +1,4 @@ -/* $Id: client.c,v 1.33 2008-06-23 16:58:49 nicm Exp $ */ +/* $Id: client.c,v 1.34 2008-07-01 19:47:02 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott @@ -93,6 +93,7 @@ retry: if (isatty(STDIN_FILENO)) { if (ioctl(STDIN_FILENO, TIOCGWINSZ, &ws) == -1) fatal("ioctl(TIOCGWINSZ)"); + data.version = PROTOCOL_VERSION; data.sx = ws.ws_col; data.sy = ws.ws_row; *data.tty = '\0'; diff --git a/server-msg.c b/server-msg.c index ad193fd7..fef163d1 100644 --- a/server-msg.c +++ b/server-msg.c @@ -1,4 +1,4 @@ -/* $Id: server-msg.c,v 1.48 2008-06-21 10:19:36 nicm Exp $ */ +/* $Id: server-msg.c,v 1.49 2008-07-01 19:47:02 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott @@ -172,7 +172,15 @@ server_msg_fn_identify(struct hdr *hdr, struct client *c) buffer_read(c->in, &data, sizeof data); term = cmd_recv_string(c->in); - log_debug("identify msg from client: %u,%u", data.sx, data.sy); + log_debug("identify msg from client: %u,%u (%d)", + data.sx, data.sy, data.version); + + if (data.version != PROTOCOL_VERSION) { +#define MSG "protocol version mismatch" + server_write_client(c, MSG_ERROR, MSG, (sizeof MSG) - 1); +#undef MSG + return (0); + } c->sx = data.sx; c->sy = data.sy; diff --git a/tmux.h b/tmux.h index 096ed456..0634de95 100644 --- a/tmux.h +++ b/tmux.h @@ -1,4 +1,4 @@ -/* $Id: tmux.h,v 1.172 2008-06-30 05:34:06 nicm Exp $ */ +/* $Id: tmux.h,v 1.173 2008-07-01 19:47:02 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott @@ -19,6 +19,8 @@ #ifndef TMUX_H #define TMUX_H +#define PROTOCOL_VERSION -1 + /* Shut up gcc warnings about empty if bodies. */ #define RB_AUGMENT(x) do {} while (0) @@ -330,7 +332,7 @@ struct buffer { #define TTY_KKEYPADOFF 22 #define TTY_KKEYPADON 23 #define TTY_MOUSEON 24 -#define TTY_MOUSEOFF 25 /* XXX merge allon/off into 1 arg? */ +#define TTY_MOUSEOFF 25 /* XXX merge all on/off into 1 arg? */ /* Message codes. */ enum hdrtype { @@ -361,6 +363,7 @@ struct msg_command_data { struct msg_identify_data { char tty[TTY_NAME_MAX]; + int version; u_int sx; u_int sy;