[Home]

Summary:ASTERISK-14398: [patch] Serious problem in pattern matching
Reporter:Jared Smith (jsmith)Labels:
Date Opened:2009-06-29 14:45:53Date Closed:2010-01-04 15:00:45.000-0600
Priority:MajorRegression?Yes
Status:Closed/CompleteComponents:PBX/pbx_config
Versions:Frequency of
Occurrence
Related
Issues:
Environment:Attachments:( 0) 20090915__issue15421.diff.txt
( 1) 20091109__issue15421__2.diff.txt
( 2) issue15421.patch.txt
Description:There appears to be a serious problem in the pattern matching in Asterisk... for some reason, it thinks the following two extensions are equivalent, when they're not.

exten => _N[2-4]X,1,NoOp(foo)
exten => _N[246]X,1,NoOp(bar)

****** STEPS TO REPRODUCE ******

Add the following to extensions.conf:

[pattern-testing]
exten => _N[2-4]X,1,NoOp(foo)
exten => _N[246]X,1,NoOp(bar)

Now go to the CLI and type:

core set verbose 2
dialplan reload
(notice that there's a warning for a duplicate extension)
dialplan show pattern-testing
(notice that only the first extension is listed)
Comments:By: Leif Madsen (lmadsen) 2009-06-30 14:17:53

I can confirm this issue as I tested the dialplan jsmith gave me, and saw the same thing.

By: Tilghman Lesher (tilghman) 2009-08-31 17:20:13

By equivalent, what do you mean?  Scoring the same?

By: dant (dant) 2009-09-01 03:18:37

e.g.

[test]
exten => _1[4-6],1,NoOp(foo)
exten => _1[468],1,NoOp(bar)
exten => _1[468],n,NoOp(bar2)

> dialplan show test
[ Context 'test' created by 'pbx_config' ]
 '_1[4-6]' =>      1. NoOp(foo)                                  [pbx_config]
                   2. NoOp(bar2)                                 [pbx_config]

-= 1 extension (2 priorities) in 1 context. =-

This is on trunk...

It seems to be that when a range and a list start with the same value and contain the same number of values that it's considered equivalent...
e.g.
[1-4] considered the same as [1789]
[2-4] considered the same as [289]

By: dant (dant) 2009-09-01 05:58:06

ext_cmp1 in pbx.c appears to be just using the minimum value and a count of values...

By: Jared Smith (jsmith) 2009-09-08 13:28:37

Tilghman,

By "equivalent" I mean that Asterisk wrongly ignores the second extension (in the example I gave above), throwing it out as it thinks it's already got that extension with priority 1.

Let me clarify:

Step 1) Add the following three lines to your dialplan:

[pattern-testing]
exten => _N[2-4]X,1,NoOp(foo)
exten => _N[246]X,1,NoOp(bar)

Step 2) Type "core set verbose 2" at the CLI.  Notice how this warning appears on your CLI:

[Sep  8 14:22:39] WARNING[26882]: pbx.c:7447 add_pri_lockopt: Unable to register extension '_N[246]X', priority 1 in 'pattern-testing', already in use

Step 3) Type "dialplan show 567@pattern-testing" at the CLI, and notice that there's nothing in the dialplan that matches that number, as Asterisk rejected the pattern match (the "bar" extension) as a duplicate of the earlier extension (the "foo" extension), when they aren't the same.

In short, it seems that Asterisk isn't smart enough to know that the digit range [2-4] is not the same as [246].

Does that clarify what I mean by "equivalent"?

By: Jared Smith (jsmith) 2009-09-21 17:36:42

I'll test the patch first thing in the morning.

By: dant (dant) 2009-09-21 21:48:08

I've applied the patch and the issue looks unresolved...

oak*CLI> dialplan show test-pat-match
[ Context 'test-pat-match' created by 'pbx_config' ]
 '_1[4-6]' =>      1. NoOp(foo)                                  [pbx_config]
                   2. NoOp(bar2)                                 [pbx_config]

[Sep 22 10:39:54] VERBOSE[25729] pbx.c:     -- Added extension '_1[4-6]' priority 1 to test-pat-match (0x8d01b10)
[Sep 22 10:39:54] WARNING[25729] pbx.c: Unable to register extension '_1[468]', priority 1 in 'test-pat-match', already in use
[Sep 22 10:39:54] VERBOSE[25729] pbx.c:     -- Added extension '_1[468]' priority 2 to test-pat-match (0x8d01b10)

By: Leif Madsen (lmadsen) 2009-11-03 14:15:35.000-0600

Changing this back to Confirmed since it appears the supplied patch does not yet resolve the issue.

By: Tilghman Lesher (tilghman) 2009-11-09 18:49:26.000-0600

Back to testing.  David Brooks and I spent some time analyzing the problem, and I came up with this patch which verifies differences in each character class before continuing through the pattern.  This should also sort correctly, with lower characters in the class (according to ASCII) sorting before higher characters (i.e. [0-8] will sort before [1-9], and [7890] will sort before [1-4]).



By: David Ruggles (thedavidfactor) 2009-11-10 08:09:05.000-0600

I have tested this patch (latest one) and can confirm it works for me. I tested against SVN rev 229007



By: Jared Smith (jsmith) 2009-11-10 11:47:04.000-0600

I tested the latest version of Trunk from SVN, patched with patch 20091109__issue15421__2.diff.txt, and it appears to be working correctly in all my tests.

Thank you for working on this!

By: Digium Subversion (svnbot) 2009-11-10 16:15:12.000-0600

Repository: asterisk
Revision: 229360

U   branches/1.4/main/pbx.c

------------------------------------------------------------------------
r229360 | tilghman | 2009-11-10 16:15:11 -0600 (Tue, 10 Nov 2009) | 12 lines

If two pattern classes start with the same digit and have the same number of characters, they will compare equal.
The example given in the issue report is that of [234] and [246], which have
these characteristics, yet they are clearly not equivalent.  The code still
uses these two characteristics, yet when the two scores compare equal, an
additional check will be done to compare all characters within the class to
verify equality.
(closes issue ASTERISK-14398)
Reported by: jsmith
Patches:
      20091109__issue15421__2.diff.txt uploaded by tilghman (license 14)
Tested by: jsmith, thedavidfactor

------------------------------------------------------------------------

http://svn.digium.com/view/asterisk?view=rev&revision=229360

By: Digium Subversion (svnbot) 2009-11-10 16:20:18.000-0600

Repository: asterisk
Revision: 229361

_U  trunk/
U   trunk/main/pbx.c

------------------------------------------------------------------------
r229361 | tilghman | 2009-11-10 16:20:18 -0600 (Tue, 10 Nov 2009) | 19 lines

Merged revisions 229360 via svnmerge from
https://origsvn.digium.com/svn/asterisk/branches/1.4

........
 r229360 | tilghman | 2009-11-10 16:09:16 -0600 (Tue, 10 Nov 2009) | 12 lines
 
 If two pattern classes start with the same digit and have the same number of characters, they will compare equal.
 The example given in the issue report is that of [234] and [246], which have
 these characteristics, yet they are clearly not equivalent.  The code still
 uses these two characteristics, yet when the two scores compare equal, an
 additional check will be done to compare all characters within the class to
 verify equality.
 (closes issue ASTERISK-14398)
  Reported by: jsmith
  Patches:
        20091109__issue15421__2.diff.txt uploaded by tilghman (license 14)
  Tested by: jsmith, thedavidfactor
........

------------------------------------------------------------------------

http://svn.digium.com/view/asterisk?view=rev&revision=229361

By: Digium Subversion (svnbot) 2009-11-10 16:23:13.000-0600

Repository: asterisk
Revision: 229363

_U  branches/1.6.0/
U   branches/1.6.0/main/pbx.c

------------------------------------------------------------------------
r229363 | tilghman | 2009-11-10 16:23:12 -0600 (Tue, 10 Nov 2009) | 26 lines

Merged revisions 229361 via svnmerge from
https://origsvn.digium.com/svn/asterisk/trunk

................
 r229361 | tilghman | 2009-11-10 16:14:22 -0600 (Tue, 10 Nov 2009) | 19 lines
 
 Merged revisions 229360 via svnmerge from
 https://origsvn.digium.com/svn/asterisk/branches/1.4
 
 ........
   r229360 | tilghman | 2009-11-10 16:09:16 -0600 (Tue, 10 Nov 2009) | 12 lines
   
   If two pattern classes start with the same digit and have the same number of characters, they will compare equal.
   The example given in the issue report is that of [234] and [246], which have
   these characteristics, yet they are clearly not equivalent.  The code still
   uses these two characteristics, yet when the two scores compare equal, an
   additional check will be done to compare all characters within the class to
   verify equality.
   (closes issue ASTERISK-14398)
    Reported by: jsmith
    Patches:
          20091109__issue15421__2.diff.txt uploaded by tilghman (license 14)
    Tested by: jsmith, thedavidfactor
 ........
................

------------------------------------------------------------------------

http://svn.digium.com/view/asterisk?view=rev&revision=229363

By: Digium Subversion (svnbot) 2009-11-10 16:23:22.000-0600

Repository: asterisk
Revision: 229364

_U  branches/1.6.1/
U   branches/1.6.1/main/pbx.c

------------------------------------------------------------------------
r229364 | tilghman | 2009-11-10 16:23:21 -0600 (Tue, 10 Nov 2009) | 26 lines

Merged revisions 229361 via svnmerge from
https://origsvn.digium.com/svn/asterisk/trunk

................
 r229361 | tilghman | 2009-11-10 16:14:22 -0600 (Tue, 10 Nov 2009) | 19 lines
 
 Merged revisions 229360 via svnmerge from
 https://origsvn.digium.com/svn/asterisk/branches/1.4
 
 ........
   r229360 | tilghman | 2009-11-10 16:09:16 -0600 (Tue, 10 Nov 2009) | 12 lines
   
   If two pattern classes start with the same digit and have the same number of characters, they will compare equal.
   The example given in the issue report is that of [234] and [246], which have
   these characteristics, yet they are clearly not equivalent.  The code still
   uses these two characteristics, yet when the two scores compare equal, an
   additional check will be done to compare all characters within the class to
   verify equality.
   (closes issue ASTERISK-14398)
    Reported by: jsmith
    Patches:
          20091109__issue15421__2.diff.txt uploaded by tilghman (license 14)
    Tested by: jsmith, thedavidfactor
 ........
................

------------------------------------------------------------------------

http://svn.digium.com/view/asterisk?view=rev&revision=229364

By: Digium Subversion (svnbot) 2009-11-10 16:23:30.000-0600

Repository: asterisk
Revision: 229366

_U  branches/1.6.2/
U   branches/1.6.2/main/pbx.c

------------------------------------------------------------------------
r229366 | tilghman | 2009-11-10 16:23:30 -0600 (Tue, 10 Nov 2009) | 26 lines

Merged revisions 229361 via svnmerge from
https://origsvn.digium.com/svn/asterisk/trunk

................
 r229361 | tilghman | 2009-11-10 16:14:22 -0600 (Tue, 10 Nov 2009) | 19 lines
 
 Merged revisions 229360 via svnmerge from
 https://origsvn.digium.com/svn/asterisk/branches/1.4
 
 ........
   r229360 | tilghman | 2009-11-10 16:09:16 -0600 (Tue, 10 Nov 2009) | 12 lines
   
   If two pattern classes start with the same digit and have the same number of characters, they will compare equal.
   The example given in the issue report is that of [234] and [246], which have
   these characteristics, yet they are clearly not equivalent.  The code still
   uses these two characteristics, yet when the two scores compare equal, an
   additional check will be done to compare all characters within the class to
   verify equality.
   (closes issue ASTERISK-14398)
    Reported by: jsmith
    Patches:
          20091109__issue15421__2.diff.txt uploaded by tilghman (license 14)
    Tested by: jsmith, thedavidfactor
 ........
................

------------------------------------------------------------------------

http://svn.digium.com/view/asterisk?view=rev&revision=229366

By: Digium Subversion (svnbot) 2010-01-04 14:57:36.000-0600

Repository: asterisk
Revision: 237493

U   branches/1.4/main/pbx.c

------------------------------------------------------------------------
r237493 | tilghman | 2010-01-04 14:57:36 -0600 (Mon, 04 Jan 2010) | 8 lines

Regression in issue ASTERISK-14398 - Pattern matching
(closes issue ASTERISK-15340)
Reported by: wdoekes
Patches:
      astsvn-16482-betterfix.diff uploaded by wdoekes (license 717)
      20091223__issue16482.diff.txt uploaded by tilghman (license 14)
Tested by: wdoekes, tilghman

------------------------------------------------------------------------

http://svn.digium.com/view/asterisk?view=rev&revision=237493

By: Digium Subversion (svnbot) 2010-01-04 14:59:01.000-0600

Repository: asterisk
Revision: 237494

_U  trunk/
U   trunk/main/pbx.c

------------------------------------------------------------------------
r237494 | tilghman | 2010-01-04 14:59:01 -0600 (Mon, 04 Jan 2010) | 15 lines

Merged revisions 237493 via svnmerge from
https://origsvn.digium.com/svn/asterisk/branches/1.4

........
 r237493 | tilghman | 2010-01-04 14:57:35 -0600 (Mon, 04 Jan 2010) | 8 lines
 
 Regression in issue ASTERISK-14398 - Pattern matching
 (closes issue ASTERISK-15340)
  Reported by: wdoekes
  Patches:
        astsvn-16482-betterfix.diff uploaded by wdoekes (license 717)
        20091223__issue16482.diff.txt uploaded by tilghman (license 14)
  Tested by: wdoekes, tilghman
........

------------------------------------------------------------------------

http://svn.digium.com/view/asterisk?view=rev&revision=237494

By: Digium Subversion (svnbot) 2010-01-04 15:00:30.000-0600

Repository: asterisk
Revision: 237495

_U  branches/1.6.0/
U   branches/1.6.0/main/pbx.c

------------------------------------------------------------------------
r237495 | tilghman | 2010-01-04 15:00:29 -0600 (Mon, 04 Jan 2010) | 22 lines

Merged revisions 237494 via svnmerge from
https://origsvn.digium.com/svn/asterisk/trunk

................
 r237494 | tilghman | 2010-01-04 14:59:01 -0600 (Mon, 04 Jan 2010) | 15 lines
 
 Merged revisions 237493 via svnmerge from
 https://origsvn.digium.com/svn/asterisk/branches/1.4
 
 ........
   r237493 | tilghman | 2010-01-04 14:57:35 -0600 (Mon, 04 Jan 2010) | 8 lines
   
   Regression in issue ASTERISK-14398 - Pattern matching
   (closes issue ASTERISK-15340)
    Reported by: wdoekes
    Patches:
          astsvn-16482-betterfix.diff uploaded by wdoekes (license 717)
          20091223__issue16482.diff.txt uploaded by tilghman (license 14)
    Tested by: wdoekes, tilghman
 ........
................

------------------------------------------------------------------------

http://svn.digium.com/view/asterisk?view=rev&revision=237495

By: Digium Subversion (svnbot) 2010-01-04 15:00:38.000-0600

Repository: asterisk
Revision: 237496

_U  branches/1.6.1/
U   branches/1.6.1/main/pbx.c

------------------------------------------------------------------------
r237496 | tilghman | 2010-01-04 15:00:37 -0600 (Mon, 04 Jan 2010) | 22 lines

Merged revisions 237494 via svnmerge from
https://origsvn.digium.com/svn/asterisk/trunk

................
 r237494 | tilghman | 2010-01-04 14:59:01 -0600 (Mon, 04 Jan 2010) | 15 lines
 
 Merged revisions 237493 via svnmerge from
 https://origsvn.digium.com/svn/asterisk/branches/1.4
 
 ........
   r237493 | tilghman | 2010-01-04 14:57:35 -0600 (Mon, 04 Jan 2010) | 8 lines
   
   Regression in issue ASTERISK-14398 - Pattern matching
   (closes issue ASTERISK-15340)
    Reported by: wdoekes
    Patches:
          astsvn-16482-betterfix.diff uploaded by wdoekes (license 717)
          20091223__issue16482.diff.txt uploaded by tilghman (license 14)
    Tested by: wdoekes, tilghman
 ........
................

------------------------------------------------------------------------

http://svn.digium.com/view/asterisk?view=rev&revision=237496

By: Digium Subversion (svnbot) 2010-01-04 15:00:45.000-0600

Repository: asterisk
Revision: 237497

_U  branches/1.6.2/
U   branches/1.6.2/main/pbx.c

------------------------------------------------------------------------
r237497 | tilghman | 2010-01-04 15:00:45 -0600 (Mon, 04 Jan 2010) | 22 lines

Merged revisions 237494 via svnmerge from
https://origsvn.digium.com/svn/asterisk/trunk

................
 r237494 | tilghman | 2010-01-04 14:59:01 -0600 (Mon, 04 Jan 2010) | 15 lines
 
 Merged revisions 237493 via svnmerge from
 https://origsvn.digium.com/svn/asterisk/branches/1.4
 
 ........
   r237493 | tilghman | 2010-01-04 14:57:35 -0600 (Mon, 04 Jan 2010) | 8 lines
   
   Regression in issue ASTERISK-14398 - Pattern matching
   (closes issue ASTERISK-15340)
    Reported by: wdoekes
    Patches:
          astsvn-16482-betterfix.diff uploaded by wdoekes (license 717)
          20091223__issue16482.diff.txt uploaded by tilghman (license 14)
    Tested by: wdoekes, tilghman
 ........
................

------------------------------------------------------------------------

http://svn.digium.com/view/asterisk?view=rev&revision=237497