Gary Johnson wrote:

> On 2022-10-12, Gary Johnson wrote:
> > I started noticing odd behavior from cscope recently, so I ran 'git
> > bisect' and found the problem at this commit:
> > 
> >     $ git bisect good
> >     dc21552c9a83413a018a91e61649cc632929d6a1 is the first bad commit
> >     commit dc21552c9a83413a018a91e61649cc632929d6a1
> >     Author: Bram Moolenaar <[email protected]>
> >     Date:   Sun Sep 25 17:03:26 2022 +0100
> > 
> >         patch 9.0.0584: cscope test with wrong executable name fails
> >         
> >         Problem:    Cscope test with wrong executable name fails.
> >         Solution:   Use /bin/sh to execute the command. (Yegappan 
> > Lakshmanan)
> > 
> >      src/if_cscope.c             | 27 ++++++++++++++++-----------
> >      src/testdir/test_cscope.vim | 14 +++++---------
> >      src/version.c               |  2 ++
> >      3 files changed, 23 insertions(+), 20 deletions(-)
> 
> I had a little time this evening, so I built 9.0.0584 and ran it
> with gdb.  I found a problem in cs_create_connection(), in
> if_cscope.c.  That function creates a command line to be executed,
> but does so incorrectly, so when that command line is converted to
> argc and argv[] for execvp(), the arguments are incorrect.
> 
> From gdb, just before execvp() is to be called:
> 
>     (gdb) p cmd
>     $6 = 0x555555f932b0 "/bin/sh -c \"exec gtags-cscope -dl -f 
> /home/gary/src/vim/vim/GTAGS\" -P/home/gary/src/vim/vim -a"
>     (gdb) p *argv@5
>     $8 = {0x555555cbb1c0 "/bin/sh", 0x555555f8d420 "-c",
>       0x555555f8dcb0 "exec gtags-cscope -dl -f /home/gary/src/vim/vim/GTAGS",
>       0x555555f8ef60 "-P/home/gary/src/vim/vim", 0x555555f93a40 "-a"}
> 
> The problem is that the quotes that close the exec command are
> placed after the -f file name instead of at the end of the complete
> command.  That causes execvp() to get the exec argument as
> 
>     exec gtags-cscope -dl -f /home/gary/src/vim/vim/GTAGS
> 
> followed by two more arguments,
> 
>     -P/home/gary/src/vim/vim
>     -a
> 
> I haven't thought through the effect of that, but it doesn't seem
> right.  The fix should be pretty simple, but I have no more time to
> work on it tonight.
> 
> Someone else can fix it if they wish, or I'll try fixing it tomorrow.

I'm glad you could locate the source of the problem.  Please try the
patch below.  How could we make a regression test for this?


*** ../vim-9.0.0735/src/if_cscope.c     2022-10-01 20:17:13.820291832 +0100
--- src/if_cscope.c     2022-10-13 10:42:26.947402744 +0100
***************
*** 954,960 ****
  
        // run the cscope command
  #ifdef UNIX
!       vim_snprintf(cmd, cmdlen, "/bin/sh -c \"exec %s -dl -f %s\"",
                                                        prog, csinfo[i].fname);
  #else
        vim_snprintf(cmd, cmdlen, "%s -dl -f %s", prog, csinfo[i].fname);
--- 954,960 ----
  
        // run the cscope command
  #ifdef UNIX
!       vim_snprintf(cmd, cmdlen, "/bin/sh -c \"exec %s -dl -f %s",
                                                        prog, csinfo[i].fname);
  #else
        vim_snprintf(cmd, cmdlen, "%s -dl -f %s", prog, csinfo[i].fname);
***************
*** 970,975 ****
--- 970,978 ----
            vim_snprintf(cmd + len, cmdlen - len, " %s", csinfo[i].flags);
        }
  # ifdef UNIX
+       // terminate the -c command argument
+       STRCAT(cmd, "\"");
+ 
        // on Win32 we still need prog
        vim_free(prog);
  # endif

-- 
LAUNCELOT: I am, sir. I am a Knight of King Arthur.
FATHER:    'Mm ... very nice castle, Camelot ... very good pig country....
                 "Monty Python and the Holy Grail" PYTHON (MONTY) PICTURES LTD

 /// Bram Moolenaar -- [email protected] -- http://www.Moolenaar.net   \\\
///                                                                      \\\
\\\        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ ///
 \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///

-- 
-- 
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 [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/vim_dev/20221013105954.7AD901C5296%40moolenaar.net.

Raspunde prin e-mail lui