diff options
author | Justin M. Keyes <justinkz@gmail.com> | 2024-09-02 15:52:18 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-09-02 15:52:18 -0700 |
commit | ae9674704ac5586438f60c883e918d448ef0e237 (patch) | |
tree | b621a6b44c8f95b3db18274b4e6d0f319cdbd391 /src/nvim/msgpack_rpc/server.c | |
parent | ef8067a19d981388a14407ea08245811cf5b3604 (diff) | |
parent | 96128a5076b7e45fc01163151401a9e2acdff565 (diff) | |
download | rneovim-ae9674704ac5586438f60c883e918d448ef0e237.tar.gz rneovim-ae9674704ac5586438f60c883e918d448ef0e237.tar.bz2 rneovim-ae9674704ac5586438f60c883e918d448ef0e237.zip |
Merge #30237 validate --listen address
Diffstat (limited to 'src/nvim/msgpack_rpc/server.c')
-rw-r--r-- | src/nvim/msgpack_rpc/server.c | 31 |
1 files changed, 20 insertions, 11 deletions
diff --git a/src/nvim/msgpack_rpc/server.c b/src/nvim/msgpack_rpc/server.c index 24bd343a34..ae34829181 100644 --- a/src/nvim/msgpack_rpc/server.c +++ b/src/nvim/msgpack_rpc/server.c @@ -28,27 +28,32 @@ static garray_T watchers = GA_EMPTY_INIT_VALUE; #endif /// Initializes the module -bool server_init(const char *listen_addr) +/// +/// @returns 0: success, 1: validation error, 2: already listening, -errno: failed to bind/listen. +int server_init(const char *listen_addr) { + bool must_free = false; ga_init(&watchers, sizeof(SocketWatcher *), 1); // $NVIM_LISTEN_ADDRESS (deprecated) - if (!listen_addr && os_env_exists(ENV_LISTEN)) { + if ((!listen_addr || listen_addr[0] == '\0') && os_env_exists(ENV_LISTEN)) { listen_addr = os_getenv(ENV_LISTEN); } - int rv = listen_addr ? server_start(listen_addr) : 1; - if (0 != rv) { + if (!listen_addr || listen_addr[0] == '\0') { listen_addr = server_address_new(NULL); - if (!listen_addr) { - return false; - } - rv = server_start(listen_addr); - xfree((char *)listen_addr); + must_free = true; + } + + if (!listen_addr) { + abort(); // Cannot happen. } + int rv = server_start(listen_addr); + if (os_env_exists(ENV_LISTEN)) { - // Unset $NVIM_LISTEN_ADDRESS, it's a liability hereafter. + // Unset $NVIM_LISTEN_ADDRESS, it's a liability hereafter. It is "input only", it must not be + // leaked to child jobs or :terminal. os_unsetenv(ENV_LISTEN); } @@ -57,7 +62,11 @@ bool server_init(const char *listen_addr) ELOG("test log message"); } - return rv == 0; + if (must_free) { + xfree((char *)listen_addr); + } + + return rv; } /// Teardown a single server |