From 7c473dc0a25fa55a09f0288b09b47fab5caee589 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Twupack?= Date: Sat, 28 Jun 2014 16:51:59 +0200 Subject: [PATCH 1/3] os/server: Fix indentation --- src/nvim/os/server.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/nvim/os/server.c b/src/nvim/os/server.c index b90e7e318b..375f3b5fa9 100644 --- a/src/nvim/os/server.c +++ b/src/nvim/os/server.c @@ -93,9 +93,9 @@ void server_start(char *endpoint) // Trim to `ADDRESS_MAX_SIZE` if (xstrlcpy(addr, endpoint, sizeof(addr)) >= sizeof(addr)) { - // TODO(aktau): since this is not what the user wanted, perhaps we - // should return an error here - EMSG2("Address was too long, truncated to %s", addr); + // TODO(aktau): since this is not what the user wanted, perhaps we + // should return an error here + EMSG2("Address was too long, truncated to %s", addr); } // Check if the server already exists From fa5615022c7c44c3d1482027b5c56849002361eb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Twupack?= Date: Sat, 28 Jun 2014 16:52:45 +0200 Subject: [PATCH 2/3] os/server: Fix TCP connection - remove unused errno - remove unused port_end - correct calculation of addr_len - use correct string length during IP copy --- src/nvim/os/server.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/src/nvim/os/server.c b/src/nvim/os/server.c index 375f3b5fa9..e5c21f3aca 100644 --- a/src/nvim/os/server.c +++ b/src/nvim/os/server.c @@ -116,21 +116,19 @@ void server_start(char *endpoint) if (addr_len > sizeof(ip) - 1) { // Maximum length of an IP address buffer is 15(eg: 255.255.255.255) - addr_len = sizeof(ip); + addr_len = sizeof(ip) - 1; } // Extract the address part - xstrlcpy(ip, addr, addr_len); + xstrlcpy(ip, addr, addr_len + 1); int port = NEOVIM_DEFAULT_TCP_PORT; if (*ip_end == ':') { - char *port_end; // Extract the port - port = strtol(ip_end + 1, &port_end, 10); - errno = 0; + port = strtol(ip_end + 1, NULL, 10); - if (errno != 0 || port == 0 || port > 0xffff) { + if (port == 0 || port > 0xffff) { // Invalid port, treat as named pipe or unix socket server_type = kServerTypePipe; } From f44e908c1176c0de7cb0bb5a591760a35149a772 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Twupack?= Date: Wed, 9 Jul 2014 22:07:58 +0200 Subject: [PATCH 3/3] os/server: Fix possible port overflow - add documentation about port being optional - parse port into long and check for valid value --- src/nvim/os/server.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/nvim/os/server.c b/src/nvim/os/server.c index e5c21f3aca..9adc867cd0 100644 --- a/src/nvim/os/server.c +++ b/src/nvim/os/server.c @@ -81,10 +81,11 @@ void server_teardown() /// Starts listening on arbitrary tcp/unix addresses specified by /// `endpoint` for API calls. The type of socket used(tcp or unix/pipe) will /// be determined by parsing `endpoint`: If it's a valid tcp address in the -/// 'ip:port' format, then it will be tcp socket, else it will be a unix -/// socket or named pipe. +/// 'ip[:port]' format, then it will be tcp socket. The port is optional +/// and if omitted will default to NEOVIM_DEFAULT_TCP_PORT. Otherwise it will +/// be a unix socket or named pipe. /// -/// @param endpoint Address of the server. Either a 'ip:port' string or an +/// @param endpoint Address of the server. Either a 'ip[:port]' string or an /// arbitrary identifier(trimmed to 256 bytes) for the unix socket or /// named pipe. void server_start(char *endpoint) @@ -126,11 +127,12 @@ void server_start(char *endpoint) if (*ip_end == ':') { // Extract the port - port = strtol(ip_end + 1, NULL, 10); - - if (port == 0 || port > 0xffff) { + long lport = strtol(ip_end + 1, NULL, 10); // NOLINT + if (lport <= 0 || lport > 0xffff) { // Invalid port, treat as named pipe or unix socket server_type = kServerTypePipe; + } else { + port = (int) lport; } }