From d637cb33da212a74636984be0ce9dfface6be6b4 Mon Sep 17 00:00:00 2001 From: Tiago Cunha Date: Tue, 28 Jul 2009 22:12:16 +0000 Subject: Sync OpenBSD patchset 181: Make all messages sent between the client and server fixed size. This is the first of two changes to make the protocol more resilient and less sensitive to other changes in the code, particularly with commands. The client now packs argv into a buffer and sends it to the server for parsing, rather than doing it itself and sending the parsed command data. As a side-effect this also removes a lot of now-unused command marshalling code. Mixing a server without this change and a client with or vice versa will cause tmux to hang or crash, please ensure that tmux is entirely killed before upgrading. --- client.c | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) (limited to 'client.c') diff --git a/client.c b/client.c index 34aad32d..a7afa80e 100644 --- a/client.c +++ b/client.c @@ -1,4 +1,4 @@ -/* $Id: client.c,v 1.56 2009-07-23 23:47:23 tcunha Exp $ */ +/* $Id: client.c,v 1.57 2009-07-28 22:12:16 tcunha Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott @@ -44,8 +44,7 @@ client_init(char *path, struct client_ctx *cctx, int cmdflags, int flags) struct winsize ws; size_t size; int mode; - struct buffer *b; - char *name; + char *name, *term; #ifdef HAVE_SETPROCTITLE char rpathbuf[MAXPATHLEN]; #endif @@ -107,20 +106,24 @@ server_started: data.flags = flags; data.sx = ws.ws_col; data.sy = ws.ws_row; - *data.tty = '\0'; + if (getcwd(data.cwd, sizeof data.cwd) == NULL) *data.cwd = '\0'; + *data.term = '\0'; + if ((term = getenv("TERM")) != NULL) { + if (strlcpy(data.term, + term, sizeof data.term) >= sizeof data.term) + *data.term = '\0'; + } + + *data.tty = '\0'; if ((name = ttyname(STDIN_FILENO)) == NULL) fatal("ttyname failed"); if (strlcpy(data.tty, name, sizeof data.tty) >= sizeof data.tty) fatalx("ttyname failed"); - b = buffer_create(BUFSIZ); - cmd_send_string(b, getenv("TERM")); - client_write_server2(cctx, MSG_IDENTIFY, - &data, sizeof data, BUFFER_OUT(b), BUFFER_USED(b)); - buffer_destroy(b); + client_write_server(cctx, MSG_IDENTIFY, &data, sizeof data); } return (0); -- cgit