Patch 7.4.421

85 views
Skip to first unread message

Bram Moolenaar

unread,
Aug 29, 2014, 5:58:19 AM8/29/14
to vim...@googlegroups.com

Patch 7.4.421
Problem: Crash when searching for "\ze*". (Urtica Dioica)
Solution: Disallow a multi after \ze and \zs.
Files: src/regexp_nfa.c, src/testdir/test64.in, src/testdir/test64.ok


*** ../vim-7.4.420/src/regexp_nfa.c 2014-05-13 19:37:19.489786520 +0200
--- src/regexp_nfa.c 2014-08-29 11:14:12.030416520 +0200
***************
*** 291,296 ****
--- 291,297 ----
static int nfa_regconcat __ARGS((void));
static int nfa_regbranch __ARGS((void));
static int nfa_reg __ARGS((int paren));
+ static int re_mult_next __ARGS((char *what));
#ifdef DEBUG
static void nfa_set_code __ARGS((int c));
static void nfa_postfix_dump __ARGS((char_u *expr, int retval));
***************
*** 1323,1332 ****
--- 1324,1337 ----
{
case 's':
EMIT(NFA_ZSTART);
+ if (re_mult_next("\\zs") == FAIL)
+ return FAIL;
break;
case 'e':
EMIT(NFA_ZEND);
nfa_has_zend = TRUE;
+ if (re_mult_next("\\ze") == FAIL)
+ return FAIL;
break;
#ifdef FEAT_SYN_HL
case '1':
***************
*** 2276,2281 ****
--- 2281,2298 ----
return OK;
}

+ /*
+ * Used in a place where no * or \+ can follow.
+ */
+ static int
+ re_mult_next(what)
+ char *what;
+ {
+ if (re_multi_type(peekchr()) == MULTI_MULT)
+ EMSG2_RET_FAIL(_("E888: (NFA regexp) cannot repeat %s"), what);
+ return OK;
+ }
+
#ifdef DEBUG
static char_u code[50];

*** ../vim-7.4.420/src/testdir/test64.in 2014-05-13 16:44:25.633695709 +0200
--- src/testdir/test64.in 2014-08-29 11:33:12.330419011 +0200
***************
*** 459,465 ****
: let text = t[2]
: let matchidx = 3
: for engine in [0, 1, 2]
! : if engine == 2 && re == 0 || engine == 1 && re ==1
: continue
: endif
: let &regexpengine = engine
--- 459,465 ----
: let text = t[2]
: let matchidx = 3
: for engine in [0, 1, 2]
! : if engine == 2 && re == 0 || engine == 1 && re == 1
: continue
: endif
: let &regexpengine = engine
***************
*** 608,613 ****
--- 608,624 ----
"ayb20gg/..\%$
"bybGo "apo "bp:"
:"
+ :" Check for detecting error
+ :set regexpengine=2
+ :for pat in [' \ze*', ' \zs*']
+ : try
+ : let l = matchlist('x x', pat)
+ : $put ='E888 NOT detected for ' . pat
+ : catch
+ : $put ='E888 detected for ' . pat
+ : endtry
+ :endfor
+ :"
:""""" Write the results """""""""""""
:/\%#=1^Results/,$wq! test.out
ENDTEST
*** ../vim-7.4.420/src/testdir/test64.ok 2014-05-13 16:44:25.633695709 +0200
--- src/testdir/test64.ok 2014-08-29 11:36:05.782419390 +0200
***************
*** 1097,1099 ****
--- 1097,1101 ----
Test END
EN
E
+ E888 detected for \ze*
+ E888 detected for \zs*
*** ../vim-7.4.420/src/version.c 2014-08-29 10:04:32.226407390 +0200
--- src/version.c 2014-08-29 11:37:15.794419543 +0200
***************
*** 743,744 ****
--- 743,746 ----
{ /* Add new patch number below this line */
+ /**/
+ 421,
/**/

--
From "know your smileys":
:----} You lie like Pinocchio

/// Bram Moolenaar -- Br...@Moolenaar.net -- http://www.Moolenaar.net \\\
/// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
\\\ an exciting new programming language -- http://www.Zimbu.org ///
\\\ help me help AIDS victims -- http://ICCF-Holland.org ///

James McCoy

unread,
Aug 29, 2014, 9:12:34 PM8/29/14
to vim...@googlegroups.com
On Fri, Aug 29, 2014 at 11:58:09AM +0200, Bram Moolenaar wrote:
>
> Patch 7.4.421
> Problem: Crash when searching for "\ze*". (Urtica Dioica)
> Solution: Disallow a multi after \ze and \zs.

This now behaves differently than the original regex engine. With
"set re=1", /\ze* matches every position. Should the behavior be
unified, one way or the other?

Cheers,
--
James
GPG Key: 4096R/331BA3DB 2011-12-05 James McCoy <jame...@jamessan.com>

Ben Fritz

unread,
Aug 30, 2014, 1:13:16 AM8/30/14
to vim...@googlegroups.com, jame...@jamessan.com
On Friday, August 29, 2014 8:12:34 PM UTC-5, James McCoy wrote:
> On Fri, Aug 29, 2014 at 11:58:09AM +0200, Bram Moolenaar wrote:
>
> >
>
> > Patch 7.4.421
>
> > Problem: Crash when searching for "\ze*". (Urtica Dioica)
>
> > Solution: Disallow a multi after \ze and \zs.
>
>
>
> This now behaves differently than the original regex engine. With
>
> "set re=1", /\ze* matches every position. Should the behavior be
>
> unified, one way or the other?
>
>

I'm pretty sure \ze* should be an invalid pattern, not match everything.

Bram Moolenaar

unread,
Aug 30, 2014, 12:10:49 PM8/30/14
to Ben Fritz, vim...@googlegroups.com, jame...@jamessan.com
Yes, that's what I thought. So we could also change the old engine.
Anybody who would have a problem with that?
Since it's a separate place in the code it can be a separate patch.

--
From "know your smileys":
(:-# Said something he shouldn't have

Ben Fritz

unread,
Aug 30, 2014, 6:06:10 PM8/30/14
to vim...@googlegroups.com, fritzo...@gmail.com, jame...@jamessan.com
On Saturday, August 30, 2014 11:10:49 AM UTC-5, Bram Moolenaar wrote:

> Ben Fritz wrote:
>
>
> > I'm pretty sure \ze* should be an invalid pattern, not match everything.
>
>
>
> Yes, that's what I thought. So we could also change the old engine.
>
> Anybody who would have a problem with that?
>


Actually, when used as the only thing in the pattern, it should probably match a literal '*' character now that I think about it; because of this text in :he /* :

Exception: When "*" is used at the start of the pattern or just after
"^" it matches the star character.

Reply all
Reply to author
Forward
0 new messages