[Home]

Summary:ASTERISK-16737: [patch] func_string FILTER contains an infinite loop
Reporter:Walter Doekes (wdoekes)Labels:
Date Opened:2010-09-27 08:41:03Date Closed:2010-10-28 11:11:54
Priority:TrivialRegression?No
Status:Closed/CompleteComponents:Functions/func_strings
Versions:Frequency of
Occurrence
Related
Issues:
Environment:Attachments:( 0) issue18060_func_strings_filter_infinite_loop.patch
Description:Hi,

func_strings FILTER() contains an infinite loop when you're using characters
above \x7f or invalid character escapes (e.g. \xgg).


Dialplan:

Set(var=abc "dëf)
NoOp(var = ${var})
Set(filtered=${FILTER(\x30-\xff,${var})}) ;; no wrapping
NoOp(filtered = ${filtered})
Set(filtered=${FILTER(\x30-\x10,${var})}) ;; wrapping
NoOp(filtered = ${filtered})
Hangup()

Output:

Set("var=abc "dëf") in new stack
NoOp("var = abc "dëf") in new stack
WARNING[21708]: func_strings.c:466 filter: Range wrapping in FILTER(\x20-\xff,abc "dëf).  This may not be what you want.
<-- Infinite loop

Expected output:

Set("var=abc "dëf") in new stack
NoOp("var = abc "dëf") in new stack
Set("filtered=abcdëf") in new stack
NoOp("filtered = abcdëf") in new stack
[2010-09-27 15:25:14] WARNING[23206]: func_strings.c:466 filter: Range wrapping in FILTER(\x30-\x10,abc "dëf).  This may not be what you want.
Set("Local/+31852100586@osvpi_world-1268;2", "filtered=abcdëf") in new stack
NoOp("Local/+31852100586@osvpi_world-1268;2", "filtered = abcdëf") in new stack
Hangup("") in new stack



I've patched func_strings.c to add a couple of (unsigned char) casts, so that
ac != c2 is actually false at one point. Otherwise ac loops from 0 to 255 while
c2 is negative.

I've also added a backwards incompatible change of setting c2 to c1 when a
parse error (invalid character escape) occurs. Otherwise I'd get the
aforementioned warning when using a range that ends at \xff.


Regards,
Walter Doekes
OSSO B.V.
Comments:By: Walter Doekes (wdoekes) 2010-09-27 08:44:33

That second Set..FILTER line in the Dialplan should've read:

Set(filtered=${FILTER(\x30-\x10,${var})}) ;; wrapping

By: Leif Madsen (lmadsen) 2010-09-28 10:57:06

Update description per your note. Thanks!

By: Digium Subversion (svnbot) 2010-10-28 11:09:42

Repository: asterisk
Revision: 293158

U   branches/1.6.2/funcs/func_strings.c

------------------------------------------------------------------------
r293158 | jpeeler | 2010-10-28 11:09:41 -0500 (Thu, 28 Oct 2010) | 11 lines

Fix infinite loop in FILTER().

Specifically when you're using characters above \x7f or invalid character
escapes (e.g. \xgg).

(closes issue ASTERISK-16737)
Reported by: wdoekes
Patches:
     issue18060_func_strings_filter_infinite_loop.patch uploaded by wdoekes (license 717)
Tested by: wdoekes

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

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

By: Digium Subversion (svnbot) 2010-10-28 11:11:09

Repository: asterisk
Revision: 293159

_U  branches/1.8/
U   branches/1.8/funcs/func_strings.c

------------------------------------------------------------------------
r293159 | jpeeler | 2010-10-28 11:11:09 -0500 (Thu, 28 Oct 2010) | 18 lines

Merged revisions 293158 via svnmerge from
https://origsvn.digium.com/svn/asterisk/branches/1.6.2

........
 r293158 | jpeeler | 2010-10-28 11:09:40 -0500 (Thu, 28 Oct 2010) | 11 lines
 
 Fix infinite loop in FILTER().
 
 Specifically when you're using characters above \x7f or invalid character
 escapes (e.g. \xgg).
 
 (closes issue ASTERISK-16737)
 Reported by: wdoekes
 Patches:
       issue18060_func_strings_filter_infinite_loop.patch uploaded by wdoekes (license 717)
 Tested by: wdoekes
........

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

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

By: Digium Subversion (svnbot) 2010-10-28 11:11:54

Repository: asterisk
Revision: 293160

_U  trunk/
U   trunk/funcs/func_strings.c

------------------------------------------------------------------------
r293160 | jpeeler | 2010-10-28 11:11:53 -0500 (Thu, 28 Oct 2010) | 25 lines

Merged revisions 293159 via svnmerge from
https://origsvn.digium.com/svn/asterisk/branches/1.8

................
 r293159 | jpeeler | 2010-10-28 11:11:08 -0500 (Thu, 28 Oct 2010) | 18 lines
 
 Merged revisions 293158 via svnmerge from
 https://origsvn.digium.com/svn/asterisk/branches/1.6.2
 
 ........
   r293158 | jpeeler | 2010-10-28 11:09:40 -0500 (Thu, 28 Oct 2010) | 11 lines
   
   Fix infinite loop in FILTER().
   
   Specifically when you're using characters above \x7f or invalid character
   escapes (e.g. \xgg).
   
   (closes issue ASTERISK-16737)
   Reported by: wdoekes
   Patches:
         issue18060_func_strings_filter_infinite_loop.patch uploaded by wdoekes (license 717)
   Tested by: wdoekes
 ........
................

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

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