From adc1f21eaee899b8ecfdb6ef3676d9a25019e4fa Mon Sep 17 00:00:00 2001 From: nicm Date: Thu, 9 Jan 2014 14:05:55 +0000 Subject: [PATCH] Three small changes from Tiago Cunha: - Check for truncation when copying path. - Don't need to use a temporary buffer in screen_set_title. - Include strerror in output when connecting to server fails. --- client.c | 3 ++- screen.c | 6 +----- tmux.c | 6 +++++- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/client.c b/client.c index 82ef9cf0..1458963c 100644 --- a/client.c +++ b/client.c @@ -232,7 +232,8 @@ client_main(int argc, char **argv, int flags) /* Initialise the client socket and start the server. */ fd = client_connect(socket_path, cmdflags & CMD_STARTSERVER); if (fd == -1) { - fprintf(stderr, "failed to connect to server\n"); + fprintf(stderr, "failed to connect to server: %s\n", + strerror(errno)); return (1); } diff --git a/screen.c b/screen.c index 76aa91c6..2b0e9fba 100644 --- a/screen.c +++ b/screen.c @@ -110,12 +110,8 @@ screen_set_cursor_colour(struct screen *s, const char *colour_string) void screen_set_title(struct screen *s, const char *title) { - char tmp[BUFSIZ]; - - strlcpy(tmp, title, sizeof tmp); - free(s->title); - s->title = xstrdup(tmp); + s->title = xstrdup(title); } /* Resize screen. */ diff --git a/tmux.c b/tmux.c index 74d827a5..c8f9e059 100644 --- a/tmux.c +++ b/tmux.c @@ -361,7 +361,11 @@ main(int argc, char **argv) } } free(label); - strlcpy(socket_path, path, sizeof socket_path); + + if (strlcpy(socket_path, path, sizeof socket_path) >= sizeof socket_path) { + fprintf(stderr, "socket path too long: %s\n", path); + exit(1); + } free(path); /* Set process title. */ -- 2.11.4.GIT