Patch 8.2.4081
Problem: CodeQL reports problem in if_cscope causing it to fail.
Solution: Use execvp() instead of execl(). Merge the header file into the
source file. (Ozaki Kiichi, closes #9519)
Files: Filelist, src/Make_cyg_ming.mak, src/Make_mvc.mak,
src/Make_vms.mms, src/Makefile, src/if_cscope.c, src/if_cscope.h,
src/testdir/test_cscope.vim
*** ../vim-8.2.4080/Filelist 2021-12-20 15:53:09.801669668 +0000
--- Filelist 2022-01-13 18:02:41.658183496 +0000
***************
*** 497,503 ****
SRC_DOS_UNIX = \
src/gui_xim.c \
src/if_cscope.c \
- src/if_cscope.h \
src/if_lua.c \
src/if_mzsch.c \
src/if_mzsch.h \
--- 497,502 ----
*** ../vim-8.2.4080/src/Make_cyg_ming.mak 2021-12-20 15:03:23.251346520 +0000
--- src/Make_cyg_ming.mak 2022-01-13 18:02:41.658183496 +0000
***************
*** 1237,1243 ****
$(OUTDIR)/gui_w32.o: gui_w32.c $(INCL) $(GUI_INCL) version.h
$(CC) -c $(CFLAGS) gui_w32.c -o $@
! $(OUTDIR)/if_cscope.o: if_cscope.c $(INCL) if_cscope.h
$(CC) -c $(CFLAGS) if_cscope.c -o $@
$(OUTDIR)/if_mzsch.o: if_mzsch.c $(INCL) $(MZSCHEME_INCL) $(MZ_EXTRA_DEP)
--- 1237,1243 ----
$(OUTDIR)/gui_w32.o: gui_w32.c $(INCL) $(GUI_INCL) version.h
$(CC) -c $(CFLAGS) gui_w32.c -o $@
! $(OUTDIR)/if_cscope.o: if_cscope.c $(INCL)
$(CC) -c $(CFLAGS) if_cscope.c -o $@
$(OUTDIR)/if_mzsch.o: if_mzsch.c $(INCL) $(MZSCHEME_INCL) $(MZ_EXTRA_DEP)
*** ../vim-8.2.4080/src/Make_mvc.mak 2021-12-20 15:03:23.251346520 +0000
--- src/Make_mvc.mak 2022-01-13 18:02:41.658183496 +0000
***************
*** 1670,1676 ****
$(OUTDIR)/gui_dwrite.obj: $(OUTDIR) gui_dwrite.cpp gui_dwrite.h
! $(OUTDIR)/if_cscope.obj: $(OUTDIR) if_cscope.c $(INCL) if_cscope.h
$(OUTDIR)/if_lua.obj: $(OUTDIR) if_lua.c $(INCL)
$(CC) $(CFLAGS_OUTDIR) $(LUA_INC) if_lua.c
--- 1670,1676 ----
$(OUTDIR)/gui_dwrite.obj: $(OUTDIR) gui_dwrite.cpp gui_dwrite.h
! $(OUTDIR)/if_cscope.obj: $(OUTDIR) if_cscope.c $(INCL)
$(OUTDIR)/if_lua.obj: $(OUTDIR) if_lua.c $(INCL)
$(CC) $(CFLAGS_OUTDIR) $(LUA_INC) if_lua.c
*** ../vim-8.2.4080/src/Make_vms.mms 2021-12-20 15:03:23.251346520 +0000
--- src/Make_vms.mms 2022-01-13 18:02:41.658183496 +0000
***************
*** 908,914 ****
if_cscope.obj : if_cscope.c vim.h [.auto]config.h feature.h os_unix.h \
ascii.h keymap.h termdefs.h macros.h structs.h regexp.h \
gui.h beval.h [.proto]
gui_beval.pro option.h ex_cmds.h proto.h \
! errors.h globals.h if_cscope.h
if_xcmdsrv.obj : if_xcmdsrv.c vim.h [.auto]config.h feature.h os_unix.h \
ascii.h keymap.h termdefs.h macros.h structs.h regexp.h \
gui.h beval.h [.proto]
gui_beval.pro option.h ex_cmds.h proto.h \
--- 908,914 ----
if_cscope.obj : if_cscope.c vim.h [.auto]config.h feature.h os_unix.h \
ascii.h keymap.h termdefs.h macros.h structs.h regexp.h \
gui.h beval.h [.proto]
gui_beval.pro option.h ex_cmds.h proto.h \
! errors.h globals.h
if_xcmdsrv.obj : if_xcmdsrv.c vim.h [.auto]config.h feature.h os_unix.h \
ascii.h keymap.h termdefs.h macros.h structs.h regexp.h \
gui.h beval.h [.proto]
gui_beval.pro option.h ex_cmds.h proto.h \
*** ../vim-8.2.4080/src/Makefile 2022-01-08 13:36:24.130742353 +0000
--- src/Makefile 2022-01-13 18:02:41.658183496 +0000
***************
*** 3922,3928 ****
objects/if_cscope.o: if_cscope.c vim.h protodef.h auto/config.h feature.h \
os_unix.h auto/osdef.h ascii.h keymap.h termdefs.h macros.h option.h beval.h \
proto/
gui_beval.pro structs.h regexp.h gui.h alloc.h ex_cmds.h spell.h \
! proto.h globals.h errors.h if_cscope.h
objects/if_xcmdsrv.o: if_xcmdsrv.c vim.h protodef.h auto/config.h feature.h \
os_unix.h auto/osdef.h ascii.h keymap.h termdefs.h macros.h option.h beval.h \
proto/
gui_beval.pro structs.h regexp.h gui.h alloc.h ex_cmds.h spell.h \
--- 3922,3928 ----
objects/if_cscope.o: if_cscope.c vim.h protodef.h auto/config.h feature.h \
os_unix.h auto/osdef.h ascii.h keymap.h termdefs.h macros.h option.h beval.h \
proto/
gui_beval.pro structs.h regexp.h gui.h alloc.h ex_cmds.h spell.h \
! proto.h globals.h errors.h
objects/if_xcmdsrv.o: if_xcmdsrv.c vim.h protodef.h auto/config.h feature.h \
os_unix.h auto/osdef.h ascii.h keymap.h termdefs.h macros.h option.h beval.h \
proto/
gui_beval.pro structs.h regexp.h gui.h alloc.h ex_cmds.h spell.h \
*** ../vim-8.2.4080/src/if_cscope.c 2022-01-04 19:57:50.930919989 +0000
--- src/if_cscope.c 2022-01-13 18:02:41.658183496 +0000
***************
*** 18,24 ****
#if defined(UNIX)
# include <sys/wait.h>
#endif
! #include "if_cscope.h"
static int cs_add(exarg_T *eap);
static int cs_add_common(char *, char *, char *);
--- 18,79 ----
#if defined(UNIX)
# include <sys/wait.h>
#endif
!
! #if defined (MSWIN)
! # ifndef WIN32_LEAN_AND_MEAN
! # define WIN32_LEAN_AND_MEAN
! # endif
! # include <windows.h>
! #endif
!
! #define CSCOPE_SUCCESS 0
! #define CSCOPE_FAILURE -1
!
! #define CSCOPE_DBFILE "cscope.out"
! #define CSCOPE_PROMPT ">> "
!
! /*
! * See ":help cscope-find" for the possible queries.
! */
!
! typedef struct {
! char * name;
! int (*func)(exarg_T *eap);
! char * help;
! char * usage;
! int cansplit; // if supports splitting window
! } cscmd_T;
!
! typedef struct csi {
! char * fname; // cscope db name
! char * ppath; // path to prepend (the -P option)
! char * flags; // additional cscope flags/options (e.g, -p2)
! #if defined(UNIX)
! pid_t pid; // PID of the connected cscope process.
! dev_t st_dev; // ID of dev containing cscope db
! ino_t st_ino; // inode number of cscope db
! #else
! # if defined(MSWIN)
! DWORD pid; // PID of the connected cscope process.
! HANDLE hProc; // cscope process handle
! DWORD nVolume; // Volume serial number, instead of st_dev
! DWORD nIndexHigh; // st_ino has no meaning in the Windows
! DWORD nIndexLow;
! # endif
! #endif
!
! FILE * fr_fp; // from cscope: FILE.
! FILE * to_fp; // to cscope: FILE.
! } csinfo_T;
!
! typedef enum { Add, Find, Help, Kill, Reset, Show } csid_e;
!
! typedef enum {
! Store,
! Get,
! Free,
! Print
! } mcmd_e;
static int cs_add(exarg_T *eap);
static int cs_add_common(char *, char *, char *);
***************
*** 811,822 ****
return CSCOPE_FAILURE;
}
! switch (csinfo[i].pid = fork())
{
- case -1:
(void)emsg(_(e_could_not_fork_for_cscope));
goto err_closing;
! case 0: // child: run cscope.
if (dup2(to_cs[0], STDIN_FILENO) == -1)
PERROR("cs_create_connection 1");
if (dup2(from_cs[1], STDOUT_FILENO) == -1)
--- 866,881 ----
return CSCOPE_FAILURE;
}
! if ((csinfo[i].pid = fork()) == -1)
{
(void)emsg(_(e_could_not_fork_for_cscope));
goto err_closing;
! }
! else if (csinfo[i].pid == 0) // child: run cscope.
! {
! char **argv = NULL;
! int argc = 0;
!
if (dup2(to_cs[0], STDIN_FILENO) == -1)
PERROR("cs_create_connection 1");
if (dup2(from_cs[1], STDOUT_FILENO) == -1)
***************
*** 856,862 ****
if ((prog = alloc(MAXPATHL + 1)) == NULL)
{
#ifdef UNIX
! return CSCOPE_FAILURE;
#else
// MSWIN
goto err_closing;
--- 915,921 ----
if ((prog = alloc(MAXPATHL + 1)) == NULL)
{
#ifdef UNIX
! exit(EXIT_FAILURE);
#else
// MSWIN
goto err_closing;
***************
*** 873,879 ****
{
vim_free(prog);
#ifdef UNIX
! return CSCOPE_FAILURE;
#else
// MSWIN
goto err_closing;
--- 932,938 ----
{
vim_free(prog);
#ifdef UNIX
! exit(EXIT_FAILURE);
#else
// MSWIN
goto err_closing;
***************
*** 892,911 ****
vim_free(prog);
vim_free(ppath);
#ifdef UNIX
! return CSCOPE_FAILURE;
#else
// MSWIN
goto err_closing;
#endif
}
! // run the cscope command; is there execl for non-unix systems?
! #if defined(UNIX)
! (void)sprintf(cmd, "exec %s -dl -f %s", prog, csinfo[i].fname);
! #else
! // MSWIN
(void)sprintf(cmd, "%s -dl -f %s", prog, csinfo[i].fname);
! #endif
if (csinfo[i].ppath != NULL)
{
(void)strcat(cmd, " -P");
--- 951,966 ----
vim_free(prog);
vim_free(ppath);
#ifdef UNIX
! exit(EXIT_FAILURE);
#else
// MSWIN
goto err_closing;
#endif
}
! // run the cscope command
(void)sprintf(cmd, "%s -dl -f %s", prog, csinfo[i].fname);
!
if (csinfo[i].ppath != NULL)
{
(void)strcat(cmd, " -P");
***************
*** 932,943 ****
PERROR(_("cs_create_connection setpgid failed"));
# endif
# endif
! if (execl("/bin/sh", "sh", "-c", cmd, (char *)NULL) == -1)
PERROR(_("cs_create_connection exec failed"));
exit(127);
// NOTREACHED
! default: // parent.
/*
* Save the file descriptors for later duplication, and
* reopen as streams.
--- 987,1003 ----
PERROR(_("cs_create_connection setpgid failed"));
# endif
# endif
! if (build_argv_from_string((char_u *)cmd, &argv, &argc) == FAIL)
! exit(EXIT_FAILURE);
!
! if (execvp(argv[0], argv) == -1)
PERROR(_("cs_create_connection exec failed"));
exit(127);
// NOTREACHED
! }
! else // parent.
! {
/*
* Save the file descriptors for later duplication, and
* reopen as streams.
***************
*** 950,959 ****
// close unused
(void)close(to_cs[0]);
(void)close(from_cs[1]);
-
- break;
}
-
#else
// MSWIN
// Create a new process to run cscope and use pipes to talk with it
--- 1010,1016 ----
*** ../vim-8.2.4080/src/if_cscope.h 2019-11-30 17:26:59.000000000 +0000
--- src/if_cscope.h 1970-01-01 00:00:00.000000000 +0000
***************
*** 1,71 ****
- /* vi:set ts=8 sts=4 sw=4 noet:
- *
- * CSCOPE support for Vim added by Andy Kahn <
ka...@zk3.dec.com>
- * Ported to Win32 by Sergey Khorev <
sergey...@gmail.com>
- *
- * The basic idea/structure of cscope for Vim was borrowed from Nvi.
- * There might be a few lines of code that look similar to what Nvi
- * has. If this is a problem and requires inclusion of the annoying
- * BSD license, then sue me; I'm not worth much anyway.
- */
-
- #if defined(FEAT_CSCOPE) || defined(PROTO)
-
- #if defined (MSWIN)
- # ifndef WIN32_LEAN_AND_MEAN
- # define WIN32_LEAN_AND_MEAN
- # endif
- # include <windows.h>
- #endif
-
- #define CSCOPE_SUCCESS 0
- #define CSCOPE_FAILURE -1
-
- #define CSCOPE_DBFILE "cscope.out"
- #define CSCOPE_PROMPT ">> "
-
- /*
- * See ":help cscope-find" for the possible queries.
- */
-
- typedef struct {
- char * name;
- int (*func)(exarg_T *eap);
- char * help;
- char * usage;
- int cansplit; // if supports splitting window
- } cscmd_T;
-
- typedef struct csi {
- char * fname; // cscope db name
- char * ppath; // path to prepend (the -P option)
- char * flags; // additional cscope flags/options (e.g, -p2)
- #if defined(UNIX)
- pid_t pid; // PID of the connected cscope process.
- dev_t st_dev; // ID of dev containing cscope db
- ino_t st_ino; // inode number of cscope db
- #else
- # if defined(MSWIN)
- DWORD pid; // PID of the connected cscope process.
- HANDLE hProc; // cscope process handle
- DWORD nVolume; // Volume serial number, instead of st_dev
- DWORD nIndexHigh; // st_ino has no meaning in the Windows
- DWORD nIndexLow;
- # endif
- #endif
-
- FILE * fr_fp; // from cscope: FILE.
- FILE * to_fp; // to cscope: FILE.
- } csinfo_T;
-
- typedef enum { Add, Find, Help, Kill, Reset, Show } csid_e;
-
- typedef enum {
- Store,
- Get,
- Free,
- Print
- } mcmd_e;
-
-
- #endif // FEAT_CSCOPE
--- 0 ----
*** ../vim-8.2.4080/src/testdir/test_cscope.vim 2021-05-24 18:37:17.529851135 +0100
--- src/testdir/test_cscope.vim 2022-01-13 18:02:41.662183493 +0000
***************
*** 246,252 ****
" Test: 'csprg' option
call assert_equal('cscope', &csprg)
set csprg=doesnotexist
! call assert_fails('cscope add Xcscope2.out', 'E609:')
set csprg=cscope
" Test: multiple cscope connections
--- 246,252 ----
" Test: 'csprg' option
call assert_equal('cscope', &csprg)
set csprg=doesnotexist
! call assert_fails('cscope add Xcscope2.out', 'E262:')
set csprg=cscope
" Test: multiple cscope connections
*** ../vim-8.2.4080/src/version.c 2022-01-13 17:42:24.171310250 +0000
--- src/version.c 2022-01-13 18:05:32.046004012 +0000
***************
*** 752,753 ****
--- 752,755 ----
{ /* Add new patch number below this line */
+ /**/
+ 4081,
/**/
--
FATHER: Make sure the Prince doesn't leave this room until I come and
get him.
FIRST GUARD: Not ... to leave the room ... even if you come and get him.
FATHER: No. Until I come and get him.
SECOND GUARD: Hic.
"Monty Python and the Holy Grail" PYTHON (MONTY) PICTURES LTD
/// Bram Moolenaar -- Br...@Moolenaar.net --
http://www.Moolenaar.net \\\
/// \\\
\\\ sponsor Vim, vote for features --
http://www.Vim.org/sponsor/ ///
\\\ help me help AIDS victims --
http://ICCF-Holland.org ///