Bug#542430: Incorrect wildcard expansion when p_sh has arguments to the shell
Bram Moolenaar
Bram at Moolenaar.net
Tue Nov 3 21:52:28 UTC 2009
James -
> The code in src/os_unix.c:mch_expand_wildcards which detects what shell
> is being used doesn't work properly if 'shell' has been set to a shell
> and arguments (e.g., "/bin/tcsh -f").
>
> 5354 else if ((len = STRLEN(p_sh)) >= 3)
> 5355 {
> 5356 if (STRCMP(p_sh + len - 3, "csh") == 0)
> 5357 shell_style = STYLE_GLOB;
> 5358 else if (STRCMP(p_sh + len - 3, "zsh") == 0)
> 5359 shell_style = STYLE_PRINT;
> 5360 }
> 5361 if (shell_style == STYLE_ECHO && strstr((char *)gettail(p_sh),
> 5362
> "sh") != NULL)
> 5363 shell_style = STYLE_VIMGLOB;
>
> Vim checks whether the last 3 characters of 'shell' are "csh". Since
> the last 3 characters of p_sh in this case are " -f", Vim then checks
> whether "sh" is in gettail(p_sh) and uses sh-compatible shell expansion.
>
> It looks like a safer approach would be to grab p_sh up to the first
> whitespace and then use gettail() on that to get the shell name. That
> should reduce the false-positive rate for setting STYLE_VIMGLOB in line
> 5363.
>
> Although, it'll still fail with shells like fish which will pass the
> strstr(..., "sh") check but not work with STYLE_VIMGLOB. fish does work
> with STYLE_ECHO, so we could add that to the special-case list.
Well, theoretically there could be a space in the path. I think
searching for the last slash, using gettail(), can comparing from that
position should work in most cases. To catch "tcsh" as well as "csh" we
can use "strstr" on gettail(). That only fails for "sh -csh", but
that's unlikely to be used :-).
--
Any sufficiently advanced technology is indistinguishable from magic.
Arthur C. Clarke
Any sufficiently advanced bug is indistinguishable from a feature.
Rich Kulawiec
/// Bram Moolenaar -- Bram at Moolenaar.net -- http://www.Moolenaar.net \\\
/// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
\\\ download, build and distribute -- http://www.A-A-P.org ///
\\\ help me help AIDS victims -- http://ICCF-Holland.org ///
More information about the pkg-vim-maintainers
mailing list