[Home]

Summary:ASTERISK-13068: [patch] Limit connect file and others will not play warnings
Reporter:Alec Davis (alecdavis)Labels:
Date Opened:2008-11-13 19:11:05.000-0600Date Closed:2008-11-17 16:25:02.000-0600
Priority:MinorRegression?No
Status:Closed/CompleteComponents:Applications/app_dial
Versions:Frequency of
Occurrence
Related
Issues:
Environment:Attachments:( 0) 20081114__bug13898__2.diff.txt
( 1) app_dial.bug13898.diff.txt
Description:LIMIT_CONNECT_FILE
LIMIT_WARNING_FILE
LIMIT_TIMEOUT_FILE

All appear to have corrupt pointers when the time comes to play the file.
They show correctly for the call.

The test macro limits the call to 20 seconds, warning at 15, frequency 10 seconds. (Note to myself, frequency too long!)

****** ADDITIONAL INFORMATION ******

Dialplan code:
exten => s,1,ChanIsAvail(${ARG1})
exten => s,2,Goto(5) ; give some room for error handling after 102
; cut away session id: "-<ID>". separator defaults to '-':
exten => s,5,Set(AVAILCHAN_NOSESSION=${CUT(AVAILCHAN,-,1)})
exten => s,n,Set(LIMIT_CONNECT_FILE=beep)
exten => s,n,Set(LIMIT_WARNING_FILE=beep)
exten => s,n,Set(LIMIT_TIMEOUT_FILE=terminated)
exten => s,n,Dial(${AVAILCHAN_NOSESSION}/${ARG2}#,,rL(20000:15000:10000))
exten => s,n,Congestion
exten => s,n,Hangup()

Console output:
   -- Executing [4888@trusted:1] Macro("SIP/8622-084bcee0", "dialout,DAHDI/g0,4888") in new stack
   -- Executing [s@macro-dialout:1] ChanIsAvail("SIP/8622-084bcee0", "DAHDI/g0") in new stack
   -- Hungup 'DAHDI/1-1'
   -- Executing [s@macro-dialout:2] Goto("SIP/8622-084bcee0", "5") in new stack
   -- Goto (macro-dialout,s,5)
   -- Executing [s@macro-dialout:5] Set("SIP/8622-084bcee0", "AVAILCHAN_NOSESSION=DAHDI/1") in new stack
   -- Executing [s@macro-dialout:6] Set("SIP/8622-084bcee0", "LIMIT_CONNECT_FILE=beep") in new stack
   -- Executing [s@macro-dialout:7] Set("SIP/8622-084bcee0", "LIMIT_WARNING_FILE=beep") in new stack
   -- Executing [s@macro-dialout:8] Set("SIP/8622-084bcee0", "LIMIT_TIMEOUT_FILE=terminated") in new stack
   -- Executing [s@macro-dialout:9] Dial("SIP/8622-084bcee0", "DAHDI/1/4888#,,rL(20000:15000:10000)") in new stack
   -- Limit Data for this call:
      > timelimit      = 20000
      > play_warning   = 15000
      > play_to_caller = yes
      > play_to_callee = no
      > warning_freq   = 10000
      > start_sound    = beep
      > warning_sound  = beep
      > end_sound      = terminated
   -- Requested transfer capability: 0x00 - SPEECH
   -- Called 1/4888#
   -- DAHDI/1-1 is proceeding passing it to SIP/8622-084bcee0
!! Unknown IE 50 (cs5, Unknown Information Element)
   -- DAHDI/1-1 is ringing
   -- DAHDI/1-1 answered SIP/8622-084bcee0
[Nov 14 14:01:08] WARNING[10154]: file.c:591 ast_openstream_full: File bcee0 does not exist in any format
[Nov 14 14:01:08] WARNING[10154]: file.c:897 ast_streamfile: Unable to open bcee0 (format 0x8 (alaw)): No such file or directory
[Nov 14 14:01:13] WARNING[10154]: file.c:591 ast_openstream_full: File °³ does not exist in any format
[Nov 14 14:01:13] WARNING[10154]: file.c:897 ast_streamfile: Unable to open °³ (format 0x8 (alaw)): No such file or directory
[Nov 14 14:01:28] WARNING[10154]: file.c:591 ast_openstream_full: File °³ does not exist in any format
[Nov 14 14:01:28] WARNING[10154]: file.c:897 ast_streamfile: Unable to open °³ (format 0x8 (alaw)): No such file or directory
   -- Hungup 'DAHDI/1-1'
 == Spawn extension (macro-dialout, s, 9) exited non-zero on 'SIP/8622-084bcee0' in macro 'dialout'
 == Spawn extension (macro-dialout, s, 9) exited non-zero on 'SIP/8622-084bcee0'
Comments:By: Alec Davis (alecdavis) 2008-11-13 21:31:50.000-0600

app_dial.bug13898.diff.txt uploaded

Cause: Using ast_strdupa(var) to set a system wide char * variable goes out of context when function returns. Checking app_dial.c from asterisk 1.2 branch didn't use ast_strdupa() to set these variables.

Suspect that app_meetme also has same problems.

working sample dialplan code:
20 second call max, at 8 seconds you get beeps every 4 seconds.

exten => s,1,ChanIsAvail(${ARG1})
exten => s,2,Goto(5) ; give some room for error handling after 102
; cut away session id: "-<ID>". separator defaults to '-':
exten => s,5,Set(AVAILCHAN_NOSESSION=${CUT(AVAILCHAN,-,1)})
exten => s,n,Set(LIMIT_CONNECT_FILE=beep)
exten => s,n,Set(LIMIT_WARNING_FILE=beep)
exten => s,n,Set(LIMIT_TIMEOUT_FILE=terminated)
exten => s,n,Dial(${AVAILCHAN_NOSESSION}/${ARG2}#,,rL(20000:12000:4000))
exten => s,n,Congestion
exten => s,n,Hangup()


console output with patch applied:

   -- Executing [4888@trusted:1] Macro("SIP/8622-08446a40", "dialout,DAHDI/g0,4888") in new stack
   -- Executing [s@macro-dialout:1] ChanIsAvail("SIP/8622-08446a40", "DAHDI/g0") in new stack
   -- Hungup 'DAHDI/1-1'
   -- Executing [s@macro-dialout:2] Goto("SIP/8622-08446a40", "5") in new stack
   -- Goto (macro-dialout,s,5)
   -- Executing [s@macro-dialout:5] Set("SIP/8622-08446a40", "AVAILCHAN_NOSESSION=DAHDI/1") in new stack
   -- Executing [s@macro-dialout:6] Set("SIP/8622-08446a40", "LIMIT_CONNECT_FILE=beep") in new stack
   -- Executing [s@macro-dialout:7] Set("SIP/8622-08446a40", "LIMIT_WARNING_FILE=beep") in new stack
   -- Executing [s@macro-dialout:8] Set("SIP/8622-08446a40", "LIMIT_TIMEOUT_FILE=terminated") in new stack
   -- Executing [s@macro-dialout:9] Dial("SIP/8622-08446a40", "DAHDI/1/4888#,,rL(20000:12000:4000)") in new stack
   -- Limit Data for this call:
      > timelimit      = 20000
      > play_warning   = 12000
      > play_to_caller = yes
      > play_to_callee = no
      > warning_freq   = 4000
      > start_sound    = beep
      > warning_sound  = beep
      > end_sound      = terminated
   -- Requested transfer capability: 0x00 - SPEECH
   -- Called 1/4888#
      > Saved useragent "Grandstream GXP2000 1.1.6.37" for peer 8620
   -- DAHDI/1-1 is proceeding passing it to SIP/8622-08446a40
!! Unknown IE 50 (cs5, Unknown Information Element)
   -- DAHDI/1-1 is ringing
   -- DAHDI/1-1 answered SIP/8622-08446a40
   -- <SIP/8622-08446a40> Playing 'beep.gsm' (language 'en')
   -- <SIP/8622-08446a40> Playing 'beep.gsm' (language 'en')
   -- <SIP/8622-08446a40> Playing 'beep.gsm' (language 'en')
   -- <SIP/8622-08446a40> Playing 'terminated.slin' (language 'en')
   -- Hungup 'DAHDI/1-1'
 == Spawn extension (macro-dialout, s, 9) exited non-zero on 'SIP/8622-08446a40' in macro 'dialout'
 == Spawn extension (macro-dialout, s, 9) exited non-zero on 'SIP/8622-08446a40'



By: Alec Davis (alecdavis) 2008-11-14 01:35:52.000-0600

Problem was introduced 123648

http://svn.digium.com/view/asterisk?view=rev&revision=123165 looked like this
var = pbx_builtin_getvar_helper(chan, "LIMIT_WARNING_FILE");
config->warning_sound = S_OR(var, "timeleft");

http://svn.digium.com/view/asterisk?view=rev&revision=123648 it now looks like this

var = pbx_builtin_getvar_helper(chan, "LIMIT_WARNING_FILE");
config->warning_sound = !ast_strlen_zero(var) ? ast_strdupa(var) : "timeleft";

By: Tilghman Lesher (tilghman) 2008-11-14 09:32:04.000-0600

Unfortunately, your patch isn't entirely safe, either, because it depends upon 3 channel variables not changing between the time they are checked and used.  This is a legitimate concern because a manager session can change the values of any channel variables at any time when the channel is unlocked.  If this were to happen, your cached pointers would be pointing towards more garbage space.  I have, however, fixed this with another patch, which allocates memory on the heap and frees those pointers at the appropriate time.

Some testing would be appreciated.

By: Alec Davis (alecdavis) 2008-11-16 04:27:21.000-0600

Tested a few test calls and they worked well.

I had noticed that there was already ast_channel_lock(chan) and  ast_channel_unlock(chan) around the code that we're working with, so cannot see how a manager session is allowed to change these channel variables.

Have applied the patch to asterisk 1.6.0rc6 and manually added the failed hunks, is now on our production box, will report back later in week.

Please also consider http://bugs.digium.com/view.php?id=13716 it's been on production box for nearly a month.

Alec

By: Tilghman Lesher (tilghman) 2008-11-16 11:15:33.000-0600

The issue is that the pointer (to a linked list item) was otherwise saved past the point when the channel was unlocked.  At any point following, prior to the use of that variable, that item could be removed from the list and deallocated (this is how channel variables are set: the previous value is removed from the list and deallocated, the new value is prepended to the head of the list).

So, if you want that value beyond the point where the channel is unlocked, you need to create a private copy of it.  This is what the previous code was doing (incorrectly, as you found out) and this is what the updated patch that I provided does, as well.

By: Digium Subversion (svnbot) 2008-11-17 16:25:02.000-0600

Repository: asterisk
Revision: 157253

U   trunk/apps/app_dial.c

------------------------------------------------------------------------
r157253 | tilghman | 2008-11-17 16:25:01 -0600 (Mon, 17 Nov 2008) | 8 lines

Can't use items duplicated off the stack frame in an element returned from
a function: in these cases, we have to use the heap, or garbage will result.
(closes issue ASTERISK-13068)
Reported by: alecdavis
Patches:
      20081114__bug13898__2.diff.txt uploaded by Corydon76 (license 14)
Tested by: alecdavis

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

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