]> granicus.if.org Git - vim/commitdiff
patch 8.2.4081: CodeQL reports problem in if_cscope causing it to fail v8.2.4081
authorichizok <gclient.gaap@gmail.com>
Thu, 13 Jan 2022 18:09:11 +0000 (18:09 +0000)
committerBram Moolenaar <Bram@vim.org>
Thu, 13 Jan 2022 18:09:11 +0000 (18:09 +0000)
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)

Filelist
src/Make_cyg_ming.mak
src/Make_mvc.mak
src/Make_vms.mms
src/Makefile
src/if_cscope.c
src/if_cscope.h [deleted file]
src/testdir/test_cscope.vim
src/version.c

index ebf19c864d27e4a308035dcca2f16dcfb9d0a172..3195a8d768b8c5639c3ad1d17c64f778172eeb8f 100644 (file)
--- a/Filelist
+++ b/Filelist
@@ -497,7 +497,6 @@ SRC_UNIX =  \
 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 \
index d9a50d243bb930e17dba49da15ad32561d15c296..451110975e4f51b0d7e123f75eb0b9862fc9fc3a 100644 (file)
@@ -1237,7 +1237,7 @@ $(OUTDIR)/gui_beval.o:    gui_beval.c $(INCL) $(GUI_INCL)
 $(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
+$(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)
index f2a45a0af8b8707463f5448152abe374149f82e3..0f6f676c496f2b3694471a62ca84da14489e1aeb 100644 (file)
@@ -1670,7 +1670,7 @@ $(OUTDIR)/gui_w32.obj:    $(OUTDIR) gui_w32.c $(INCL) $(GUI_INCL) version.h
 
 $(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_cscope.obj: $(OUTDIR) if_cscope.c  $(INCL)
 
 $(OUTDIR)/if_lua.obj: $(OUTDIR) if_lua.c  $(INCL)
        $(CC) $(CFLAGS_OUTDIR) $(LUA_INC) if_lua.c
index 54aa4c3a72244ccbed7ad6b67a2ddee87150f004..5ee4aabaebd3646cfad156fbb2486bf89211fb47 100644 (file)
@@ -908,7 +908,7 @@ highlight.obj : highlight.c vim.h [.auto]config.h feature.h os_unix.h \
 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
+ 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 \
index c65781ec59d1964e90469152c4b8f670fc1b2d9f..cdb491be257ccf65f7946fe7a21b0b5823bbd631 100644 (file)
@@ -3922,7 +3922,7 @@ objects/highlight.o: highlight.c vim.h protodef.h auto/config.h feature.h \
 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
+ 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 \
index 28f7db2d27353aa27c2677eecd6cbf411d101876..ccccb518b3fcce8553501d9efcd1b8ac0b661a6c 100644 (file)
 #if defined(UNIX)
 # include <sys/wait.h>
 #endif
-#include "if_cscope.h"
+
+#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,12 +866,16 @@ err_closing:
        return CSCOPE_FAILURE;
     }
 
-    switch (csinfo[i].pid = fork())
+    if ((csinfo[i].pid = fork()) == -1)
     {
-    case -1:
        (void)emsg(_(e_could_not_fork_for_cscope));
        goto err_closing;
-    case 0:                            // child: run cscope.
+    }
+    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,7 +915,7 @@ err_closing:
        if ((prog = alloc(MAXPATHL + 1)) == NULL)
        {
 #ifdef UNIX
-           return CSCOPE_FAILURE;
+           exit(EXIT_FAILURE);
 #else
            // MSWIN
            goto err_closing;
@@ -873,7 +932,7 @@ err_closing:
            {
                vim_free(prog);
 #ifdef UNIX
-               return CSCOPE_FAILURE;
+               exit(EXIT_FAILURE);
 #else
                // MSWIN
                goto err_closing;
@@ -892,20 +951,16 @@ err_closing:
            vim_free(prog);
            vim_free(ppath);
 #ifdef UNIX
-           return CSCOPE_FAILURE;
+           exit(EXIT_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
+       // run the cscope command
        (void)sprintf(cmd, "%s -dl -f %s", prog, csinfo[i].fname);
-#endif
+
        if (csinfo[i].ppath != NULL)
        {
            (void)strcat(cmd, " -P");
@@ -932,12 +987,17 @@ err_closing:
            PERROR(_("cs_create_connection setpgid failed"));
 #  endif
 # endif
-       if (execl("/bin/sh", "sh", "-c", cmd, (char *)NULL) == -1)
+       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
-    default:   // parent.
+    }
+    else       // parent.
+    {
        /*
         * Save the file descriptors for later duplication, and
         * reopen as streams.
@@ -950,10 +1010,7 @@ err_closing:
        // 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
diff --git a/src/if_cscope.h b/src/if_cscope.h
deleted file mode 100644 (file)
index 5c031a3..0000000
+++ /dev/null
@@ -1,71 +0,0 @@
-/* vi:set ts=8 sts=4 sw=4 noet:
- *
- * CSCOPE support for Vim added by Andy Kahn <kahn@zk3.dec.com>
- * Ported to Win32 by Sergey Khorev <sergey.khorev@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
index c01ca3243e26a43f3544c6b4c9be6e8871422246..ba194196e3cd5854ad4b4d48e1bd6bb6b79648de 100644 (file)
@@ -246,7 +246,7 @@ func Test_cscopeWithCscopeConnections()
     " Test: 'csprg' option
     call assert_equal('cscope', &csprg)
     set csprg=doesnotexist
-    call assert_fails('cscope add Xcscope2.out', 'E609:')
+    call assert_fails('cscope add Xcscope2.out', 'E262:')
     set csprg=cscope
 
     " Test: multiple cscope connections
index 00892328c1dc9bcb1b3a96cdb3242355060efece..67a258a98ff169b1dce9f9f1d739d2f7134767f3 100644 (file)
@@ -750,6 +750,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    4081,
 /**/
     4080,
 /**/