patch 9.1.1661: Coverity finds a few issues in clientserver.c Commit: https://github.com/vim/vim/commit/c0a3eda6ba2f7e266c110f43566c8264852a3559 Author: Foxe Chen <chen.f...@gmail.com> Date: Wed Aug 20 22:00:41 2025 +0200
patch 9.1.1661: Coverity finds a few issues in clientserver.c Problem: Coverity finds a few issues in clientserver.c (also by Tony Mechelynck) Solution: Fix issues and warnings (Foxe Chen) closes: #18057 Signed-off-by: Foxe Chen <chen.f...@gmail.com> Signed-off-by: Christian Brabandt <c...@256bit.org> diff --git a/src/clientserver.c b/src/clientserver.c index bc3fe2d3d..6ff3ad7e9 100644 --- a/src/clientserver.c +++ b/src/clientserver.c @@ -330,7 +330,7 @@ cmdsrv_main( char_u *res; int i; char_u *sname; - int ret; + int ret = -1; int didone = FALSE; int exiterr = 0; char **newArgV = argv + 1; @@ -904,19 +904,19 @@ remote_common(typval_T *argvars, typval_T *rettv, int expr) if (clientserver_method == CLIENTSERVER_METHOD_SOCKET) if (socket_server_send(server_name, keys, &r, &client, expr, timeout * 1000, TRUE) < 0) - goto stuff; + goto fail; #endif #ifdef FEAT_X11 if (clientserver_method == CLIENTSERVER_METHOD_X11) if (serverSendToVim(X_DISPLAY, server_name, keys, &r, &w, expr, timeout, 0, TRUE) < 0) - goto stuff; + goto fail; #endif # endif #if !defined(MSWIN) if (FALSE) { -stuff: +fail: #else { #endif @@ -949,6 +949,7 @@ stuff: idvar = tv_get_string_chk(&argvars[2]); if (idvar != NULL && *idvar != NUL) { + str[0] = NUL; #ifdef MSWIN sprintf((char *)str, PRINTF_HEX_LONG_U, (long_u)w); #else diff --git a/src/os_unix.c b/src/os_unix.c index cc1db3d19..b1b7b33dc 100644 --- a/src/os_unix.c +++ b/src/os_unix.c @@ -9326,6 +9326,7 @@ socket_server_init(char_u *name) vim_free(path); return OK; fail: + close(fd); vim_free(path); socket_server_uninit(); return FAIL; @@ -9844,7 +9845,10 @@ socket_server_connect(char_u *name, char_u **path, int silent) socket_fd = socket(AF_UNIX, SOCK_STREAM, 0); if (socket_fd == -1) - goto fail; + { + vim_free(socket_path); + return -1; + } addr.sun_family = AF_UNIX; vim_snprintf(addr.sun_path, sizeof(addr.sun_path), "%s", socket_path); @@ -9856,7 +9860,9 @@ socket_server_connect(char_u *name, char_u **path, int silent) if (!silent) semsg(_(e_socket_server_failed_connecting), socket_path, strerror(errno)); - goto fail; + close(socket_fd); + vim_free(socket_path); + return -1; } if (path != NULL) @@ -9865,10 +9871,6 @@ socket_server_connect(char_u *name, char_u **path, int silent) vim_free(socket_path); return socket_fd; -fail: - close(socket_fd); - vim_free(socket_path); - return -1; } @@ -10337,7 +10339,7 @@ socket_server_exec_cmd(ss_cmd_T *cmd, int fd) cmd->cmd_type == SS_CMD_TYPE_KEYSTROKES) { // Either an expression or keystrokes. - if (socket_server_valid() && enc != NULL) + if (socket_server_valid() && enc != NULL && str != NULL) { str = serverConvert(enc, str, &to_free); diff --git a/src/testdir/test_remote.vim b/src/testdir/test_remote.vim index 742c8e283..af70f2217 100644 --- a/src/testdir/test_remote.vim +++ b/src/testdir/test_remote.vim @@ -15,6 +15,19 @@ func Verify_remote_feature_works() enew let buf = RunVimInTerminal('--servername XVIMTEST', {'rows': 8}) call TermWait(buf) + + " For some reason when the socket server is being used, the terminal Vim never + " receives the `:w! XVimRemoteTest.txt` command from term_sendkeys. + if has('socketserver') && !has('X11') + if match(serverlist(), "XVIMTEST") == -1 + call StopVimInTerminal(buf) + throw s:skip + endif + + let s:remote = 1 + return + endif + let cmd = GetVimCommandCleanTerm() .. '--serverlist' call term_sendkeys(buf, ":r! " .. cmd .. "\<CR>") call TermWait(buf) diff --git a/src/version.c b/src/version.c index 855322963..bb3810302 100644 --- a/src/version.c +++ b/src/version.c @@ -724,6 +724,8 @@ static char *(features[]) = static int included_patches[] = { /* Add new patch number below this line */ +/**/ + 1661, /**/ 1660, /**/ -- -- You received this message from the "vim_dev" maillist. Do not top-post! Type your reply below the text you are replying to. For more information, visit http://www.vim.org/maillist.php --- You received this message because you are subscribed to the Google Groups "vim_dev" group. To unsubscribe from this group and stop receiving emails from it, send an email to vim_dev+unsubscr...@googlegroups.com. To view this discussion visit https://groups.google.com/d/msgid/vim_dev/E1uopD6-009VRU-RQ%40256bit.org.