patch to fix overlapping strcpy(...) in vim-7.1.156

2007-11-16 Fir de Conversatie Dominique Pelle
Valgrind memory checker finds the following error in vim-7.1.156:

==6314== Source and destination overlap in strcpy(0x4B81DD0, 0x4B81DD1)
==6314==at 0x40245D2: strcpy (mc_replace_strmem.c:106)
==6314==by 0x80986CA: do_sub (ex_cmds.c:4888)
==6314==by 0x80A50EA: do_one_cmd (ex_docmd.c:2621)
==6314==by 0x80A293A: do_cmdline (ex_docmd.c:1099)
==6314==by 0x8128CA6: nv_colon (normal.c:5175)
==6314==by 0x812226A: normal_cmd (normal.c:1148)
==6314==by 0x80E5245: main_loop (main.c:1181)
==6314==by 0x80E4D95: main (main.c:940)

I can reproduce it when using  in the substituted string.

For example:

  $ echo foo > test.txt
  $ valgrind ./vim -u NONE -U NONE -c '%s/^/^Ma' test.txt 2>vg.log

(where ^M can be typed with )

I attach a simple patch.

I am using vim on Linux, built without optimizations -O0.

-- Dominique

--~--~-~--~~~---~--~~
You received this message from the "vim_dev" maillist.
For more information, visit http://www.vim.org/maillist.php
-~--~~~~--~~--~--~---

Index: ex_cmds.c
===
RCS file: /cvsroot/vim/vim7/src/ex_cmds.c,v
retrieving revision 1.97
diff -c -r1.97 ex_cmds.c
*** ex_cmds.c	8 Nov 2007 19:48:52 -	1.97
--- ex_cmds.c	17 Nov 2007 06:30:58 -
***
*** 4885,4891 
  			++line2;
  			/* move the cursor to the new line, like Vi */
  			++curwin->w_cursor.lnum;
! 			STRCPY(new_start, p1 + 1);	/* copy the rest */
  			p1 = new_start - 1;
  			}
  		}
--- 4885,4892 
  			++line2;
  			/* move the cursor to the new line, like Vi */
  			++curwin->w_cursor.lnum;
! 			/* copy the rest */
! 			mch_memmove(new_start, p1 + 1, STRLEN(p1 + 1) + 1);
  			p1 = new_start - 1;
  			}
  		}


Re: non-posix compliant shells

2007-11-16 Fir de Conversatie Vladimir Marek
> > Maybe I misunderstood here. If you want to tell vim to use /bin/sh all
> > the time, just put "set shell=" unconditionally into your vimrc.
> 
> That's clear, but I'd like to use fish and not /bin/sh as shell.

> > You can always run
> > 
> > :!fish
> 
> That's the problem - it does not work - and you can try for yourself.

Id does work for me, through there is really some problem.

I do have

:set shell=/bin/sh

This just says to vim, to use /bin/sh for executing external commands.
It does not say which shell I should use for my interactive work.

Then I run

:!fish

Welcome to fish, the friendly interactive shell
Type help for instructions on how to use fish
[EMAIL PROTECTED] ~> echo $version
1.22.3
[EMAIL PROTECTED] ~>

And I do have fish shell.

Now the problem is, when I exit

[EMAIL PROTECTED] ~> exit

Good bye

[1]+  Stopped vi

It somehow stops vim. When I bring it to foreground (using fg), vi
continues normally.


> > > After switching to xmonad WM, i (mostly) replaced gvim with vim
> > > running it in fullscreen session and I'd be more than happy being
> > > able to jump into my default (fish) shell to perform e.g.
> > > darcs-related tasks and not having to switch to another fish term.
> > 
> > Let's try to state the question differently. What's wrong if you
> > :set shell=/bin/sh ? Some part of vim behaves differently than what
> > would you want ?
> 
> I'd like to be able to do :set shell=/usr/bin/fish and use it.

I still don't see the reason. If you ":set shell=/usr/bin/fish", it does
not change vim behavior, only if you run external commands like
":%!sort" it will try to use fish instead of sh.

Can you be here more specific and give example of what behaves
differently ?

-- 
Vlad


pgpYiynhDiAki.pgp
Description: PGP signature


Re: non-posix compliant shells

2007-11-16 Fir de Conversatie Gour
On Fri, 16 Nov 2007 16:10:40 +0100
Vladimir Marek <[EMAIL PROTECTED]> wrote:

> This just says to vim, to use /bin/sh for executing external commands.
> It does not say which shell I should use for my interactive work.

Hmm, then I must wrongly understood the vim's help:

:sh[ell]This command starts a shell.  When the shell
exits (after the "exit" command) you return to Vim.  The name for the
shell command comes from 'shell' option.


afaiu, the 'shell' option decided which shell will vim use with :sh
command, or am I wrong?

> It somehow stops vim. When I bring it to foreground (using fg), vi
> continues normally.

I've problem bringing vim back. Can you try to make experiment by using
fish as default shell?

> I still don't see the reason. If you ":set shell=/usr/bin/fish", it
> does not change vim behavior, only if you run external commands like
> ":%!sort" it will try to use fish instead of sh.
> 
> Can you be here more specific and give example of what behaves
> differently ?

Well, as said above - I just want to be able to be put in fish shell
when I execute :sh in vim.


Maybe I'm missing something...

Sincerely,
Gour


signature.asc
Description: PGP signature


Re: non-posix compliant shells

2007-11-16 Fir de Conversatie Charles E Campbell Jr

James Vega wrote:

>On Fri, Nov 16, 2007 at 10:01:03AM -0500, Charles E Campbell Jr wrote:
>  
>
>>gour wrote:
>>
>>
>>>I hit the problem in vim yesterday when I wanted to run fish shell
>>>(http://fishshell.org) within vim and soon got informed that the
>>>problem is
>>>  
>>>
>>Exactly what is the problem?  Are you trying to use system(), or filters 
>>(:!), or what?
>>
>>
>
>It's easily observable using system() but anything else that tries to
>invoke commands in a subshell and capture the output will run into the
>same problem.  Vim is running this command
>
>  /usr/bin/fish -c "(ls /tmp) >/tmp/v244859/1"
>
>fish doesn't allow you to use a subshell command as the actual command
>being run.  That is, the above command-line errors out (in an
>interactive shell) with "Illegal command name (ls /tmp)".  Vim should
>simply be running it as
>
>  /usr/bin/fish -c "ls /tmp >/tmp/v244859/1"
>
>From what I've seen in Vim's shell-related options, there isn't anything
>to affect this.
>  
>
I wrote a small C program:

/* myecho.c: this program simply echos its arguments to 
 *   Author: Charles E. Campbell, Jr.
 *   Date:   Nov 16, 2007
 */
#include 
#include 

/* - */
/* main: {{{2 */
int main(
  intargc,
  char **argv)
{
char  buf[256];
char *b;
int   i;
FILE *fp;

for(i= 0, b= buf; i < argc; ++i) {
sprintf(b,"%s%s",
  argv[i],
  (i == argc-1)? "" : " ");
b+= strlen(b);
}

fp= fopen("myecho.out","w");
fprintf(fp,"%s\n",buf);
fclose(fp);

return 0;
}

compiled it (to myecho), brought up Vim, then :set 
shell=/home/cec/myecho .  I then tried

   :!ls

and myecho.out was:

   /home/cec/myecho -c ls /tmp

No subshells there!  I then tried

   :call system("ls /tmp")

and got:  (an error message about not being able to open E484: Can't 
open file /tmp/v238233/2, because myecho doesn't do such things)

   /home/cec/myecho -c (ls /tmp) >/tmp/v238167/2

Finally I tried filtering (one line, ls /tmp, used V!ls).  Got the now 
expected E484, and myecho.out shows:

   /home/cec/myecho -c (ls) < /tmp/v238333/2 >/tmp/v238333/3

So: two out of three methods of using the shell do seem to use subshells.

Regards,
Chip Campbell


--~--~-~--~~~---~--~~
You received this message from the "vim_dev" maillist.
For more information, visit http://www.vim.org/maillist.php
-~--~~~~--~~--~--~---



Re: non-posix compliant shells

2007-11-16 Fir de Conversatie Gour
On Fri, 16 Nov 2007 17:36:52 +0100
Vladimir Marek <[EMAIL PROTECTED]> wrote:


> Sure, what are your exact steps ?

chsh and then /usr/bin/fish

Sincerely,
Gour



 


signature.asc
Description: PGP signature


Re: non-posix compliant shells

2007-11-16 Fir de Conversatie James Vega
On Fri, Nov 16, 2007 at 10:31:20AM -0500, James Vega wrote:
> Vim is running this command
> 
>   /usr/bin/fish -c "(ls /tmp) >/tmp/v244859/1"
> 
> fish doesn't allow you to use a subshell command as the actual command
> being run.  That is, the above command-line errors out (in an
> interactive shell) with "Illegal command name (ls /tmp)".  Vim should
> simply be running it as
> 
>   /usr/bin/fish -c "ls /tmp >/tmp/v244859/1"

Actually, this doesn't stick to the original intent of the command Vim
is actually running.  The following is probably a better implementation

  /usr/bin/fish -c "begin; ls /tmp; end >/tmp/v244859/1"

since that allows multiple commands to be run and the output of all of
them will be redirected to the file.

James
-- 
GPG Key: 1024D/61326D40 2003-09-02 James Vega <[EMAIL PROTECTED]>


signature.asc
Description: Digital signature


Re: non-posix compliant shells

2007-11-16 Fir de Conversatie James Vega
On Fri, Nov 16, 2007 at 10:01:03AM -0500, Charles E Campbell Jr wrote:
> 
> gour wrote:
> 
> >I hit the problem in vim yesterday when I wanted to run fish shell
> >(http://fishshell.org) within vim and soon got informed that the
> >problem is
> >  
> >
> Exactly what is the problem?  Are you trying to use system(), or filters 
> (:!), or what?

It's easily observable using system() but anything else that tries to
invoke commands in a subshell and capture the output will run into the
same problem.  Vim is running this command

  /usr/bin/fish -c "(ls /tmp) >/tmp/v244859/1"

fish doesn't allow you to use a subshell command as the actual command
being run.  That is, the above command-line errors out (in an
interactive shell) with "Illegal command name (ls /tmp)".  Vim should
simply be running it as

  /usr/bin/fish -c "ls /tmp >/tmp/v244859/1"

From what I've seen in Vim's shell-related options, there isn't anything
to affect this.

James
-- 
GPG Key: 1024D/61326D40 2003-09-02 James Vega <[EMAIL PROTECTED]>


signature.asc
Description: Digital signature


Re: non-posix compliant shells

2007-11-16 Fir de Conversatie Vladimir Marek
> Hmm, then I must wrongly understood the vim's help:
> 
> :sh[ell]  This command starts a shell.  When the shell
> exits (after the "exit" command) you return to Vim.  The name for the
> shell command comes from 'shell' option.

No, you understand correctly. I just don't use for fish invocation
:set shell=/usr/bin/fish
:shell

but rather
:!fish

:! executes any program, so why not fish


> afaiu, the 'shell' option decided which shell will vim use with :sh
> command, or am I wrong?

Yes, that's correct, and now I understand where your problem is. :!fish
is workaround. Another workaround might be

:command Sh :!fish

and use (capital S)

:Sh


> > It somehow stops vim. When I bring it to foreground (using fg), vi
> > continues normally.
> 
> I've problem bringing vim back. Can you try to make experiment by using
> fish as default shell?

Sure, what are your exact steps ?

-- 
Vlad


pgptP9LhGdnk1.pgp
Description: PGP signature


Re: non-posix compliant shells

2007-11-16 Fir de Conversatie Vladimir Marek
Hi,

> Googling a bit brought me to this thread http://tinyurl.com/3cgns7
> which provides 'workaround', i.e. putting something like:

Snip from the thread:

= cut ==
i still think that the best way would be to teach app developers that
they must not expect that shells are posix compatible but should rather
explicitly call a posix shell if they need one.


And you are doing exactly that by having this setting.

> if $SHELL =~ 'fish'
>set shell=/bin/sh
> endif


> However, the 'workaround' means only to be able to use shell with vim
> when one has fish as default shell, but not using fish.

Maybe I misunderstood here. If you want to tell vim to use /bin/sh all
the time, just put "set shell=" unconditionally into your vimrc.


> Short discussion on #vim confirmed that, somehow, vim has posix-
> compliancy hardwired, so the question is if there is some prospect in
> the future that vim can execute posx non-compliant shells like fish?

And what interface exactly should vim use ? Every non-posix shell will
probably have different one, so you would have to support them one by
one.


> After switching to xmonad WM, i (mostly) replaced gvim with vim
> running it in fullscreen session and I'd be more than happy being able
> to jump into my default (fish) shell to perform e.g. darcs-related
> tasks and not having to switch to another fish term.

You can always run

:!fish

Let's try to state the question differently. What's wrong if you
:set shell=/bin/sh ? Some part of vim behaves differently than what
would you want ?


> Moreover, after 'discovering' the shell-problem, I was quickly
> ridiculed  by some emxxx users :-(

I don't think that emacs supports fish (but I might be wrong). The
advantage which emacs has here, is that it can run commandline in a
window, so you may start fish (or perl, python, etc.) in window and
still edit text in other window.

Hope this helps

-- 
Vlad


pgphCluLy1L0Y.pgp
Description: PGP signature


Re: non-posix compliant shells

2007-11-16 Fir de Conversatie Charles E Campbell Jr

gour wrote:

>I hit the problem in vim yesterday when I wanted to run fish shell
>(http://fishshell.org) within vim and soon got informed that the
>problem is
>  
>
Exactly what is the problem?  Are you trying to use system(), or filters 
(:!), or what?  Please give an example of something you're trying to do 
that the choice of shell impacts.  Vim has a number of options that are 
shell related, perhaps you need to find the right set for fish:

"  set shell : name of shell to use for ! and :! commands
"  set shq   : shellquote   -- how to quote characters about the cmd 
passed to shell
"  set sxq   : shellxquote  -- includes redirection (shellquote excludes 
that)
"  set ssl   : shellslash   -- when set, forward slash used to expand 
file names
"  set shcf  : shellcmdflag -- flag passed to shell to execute ! and :! 
commands
"  set sp: shellpipe-- string used to put output of :make into 
errorfile
"  set srr   : shellredir   -- string used to put output of filter cmd 
into temporary file

As an example of a shell that's certainly not Posix compliant -- note 
that vim works under VMS.  Its paths aren't '/' separated (ex. 
[abc.def.ghi]file.c )

Regards,
Chip Campbell


--~--~-~--~~~---~--~~
You received this message from the "vim_dev" maillist.
For more information, visit http://www.vim.org/maillist.php
-~--~~~~--~~--~--~---



Re: non-posix compliant shells

2007-11-16 Fir de Conversatie Gour
On Fri, 16 Nov 2007 12:13:37 +0100
Vladimir Marek <[EMAIL PROTECTED]> wrote:


> Maybe I misunderstood here. If you want to tell vim to use /bin/sh all
> the time, just put "set shell=" unconditionally into your vimrc.

That's clear, but I'd like to use fish and not /bin/sh as shell.

> And what interface exactly should vim use ? 

No idea.

> Every non-posix shell will probably have different one, so you would
> have to support them one by one.

Recently I hit the similar problem with darcs where one command was
chaining shell commands with '&&' which was not understood by fish, but
devs found elegant solution.


> > After switching to xmonad WM, i (mostly) replaced gvim with vim
> > running it in fullscreen session and I'd be more than happy being
> > able to jump into my default (fish) shell to perform e.g.
> > darcs-related tasks and not having to switch to another fish term.
> 
> You can always run
> 
> :!fish

That's the problem - it does not work - and you can try for yourself.

> Let's try to state the question differently. What's wrong if you
> :set shell=/bin/sh ? Some part of vim behaves differently than what
> would you want ?

I'd like to be able to do :set shell=/usr/bin/fish and use it.

> I don't think that emacs supports fish (but I might be wrong). The
> advantage which emacs has here, is that it can run commandline in a
> window, so you may start fish (or perl, python, etc.) in window and
> still edit text in other window.

I dunno, never really tried to use emacs, but I'm told it does not have
problem with fish.

> Hope this helps

Thank you for your input.

Sincerely,
Gour
 


signature.asc
Description: PGP signature


Re: E501 with comment in Ex?

2007-11-16 Fir de Conversatie Tony Mechelynck

Michael Hordijk wrote:
> Using ex, I'm seeing the following odd behavior when entering a comment:
> 
> [[[
> $ echo blah > foo.txt
> $ ex foo.txt
> 
> "foo.txt" 1L, 5C
> Entering Ex mode.  Type "visual" to go to Normal mode.
> :"
> E501: At end-of-file
> :
> ]]]
> 
> This used to be fine in older versions of vim (say 6.3).  The change
> that seems to be responsible would be:
> 
> [[[
> --- ex_docmd.c  2005/02/12 14:18:27 1.31
> +++ ex_docmd.c  2005/02/22 08:32:32 1.32
> @@ -1671,7 +1688,10 @@
> 
> /* ignore comment and empty lines */
> if (*ea.cmd == '"' || *ea.cmd == NUL)
> +   {
> +   ex_pressedreturn = TRUE;
> goto doend;
> +   }
> 
>  /*
>   * 2. handle command modifiers.
> 
> ]]]
> 
> Which is rev 1.32 of vim7/src/ex_docmd.c.  The revlog for 1.32 of
> ex_docmd.c is "updated for version 7.0051" which leads me to believe
> this is from another patch or repository collection somewhere (not
> familiar with how vim's repositories are managed).
> 
> I would expect that comments would not trigger an EOF error.  It causes
> ex to exit with an error code if you put a comment in script that you
> feed in.  It also appears that other versions of ex (FreeBSD, Sun) don't
> generate this error.
> 
> Thoughts?
> 
> - michael

"7.0051" sounds like a "snapshot" number of 7.0aa ALPHA.

Your "line 1688" (the empty line before "/* ignore comment and empty lines 
*/") appears as line 1742 in my current version of ex_docmd.c for Vim 7.1. The 
latest patch applying to that file is 7.1.156.


Best regards,
Tony.
-- 
The owner of a large furniture store in the mid-west arrived in France
on a buying trip.  As he was checking into a hotel he struck up an
acquaintance with a beautiful young lady.  However, she only spoke
French and he only spoke English, so each couldn't understand a word
the other spoke.  He took out a pencil and a notebook and drew a
picture of a taxi.  She smiled, nodded her head and they went for a
ride in the park.  Later, he drew a picture of a table in a restaurant
with a question mark and she nodded, so they went to dinner.  After
dinner he sketched two dancers and she was delighted.  They went to
several nightclubs, drank champagne, danced and had a glorious
evening.  It had gotten quite late when she motioned for the pencil and
drew a picture of a four-poster bed.  He was dumbfounded, and has never
be able to understand how she knew he was in the furniture business.

--~--~-~--~~~---~--~~
You received this message from the "vim_dev" maillist.
For more information, visit http://www.vim.org/maillist.php
-~--~~~~--~~--~--~---



non-posix compliant shells

2007-11-16 Fir de Conversatie gour

Hi!

I hit the problem in vim yesterday when I wanted to run fish shell
(http://fishshell.org) within vim and soon got informed that the
problem is
that Vim expects to see posix-compliant shell which fish is not.

Googling a bit brought me to this thread http://tinyurl.com/3cgns7
which
provides 'workaround', i.e. putting something like:

if $SHELL =3D~ 'fish'
   set shell=3D/bin/sh
endif

at the beginning of one's ~/.vimrc.

However, the 'workaround' means only to be able to use shell with vim
when one
has fish as default shell, but not using fish.

Short discussion on #vim confirmed that, somehow, vim has posix-
compliancy
hardwired, so the question is if there is some prospect in the future
that vim
can execute posx non-compliant shells like fish?

After switching to xmonad WM, i (mostly) replaced gvim with vim
running it in
fullscreen session and I'd be more than happy being able to jump into
my
default (fish) shell to perform e.g. darcs-related tasks and not
having to
switch to another fish term.

Moreover, after 'discovering' the shell-problem, I was quickly
ridiculed  by some emxxx users :-(


Sincerely,
Gour

--~--~-~--~~~---~--~~
You received this message from the "vim_dev" maillist.
For more information, visit http://www.vim.org/maillist.php
-~--~~~~--~~--~--~---