Summary:ASTERISK-17074: No audio on incoming calls when callerid (database cidname) was saved with a newline
Reporter:xerofun (xerofun)Labels:
Date Opened:2010-12-07 08:30:17.000-0600Date Closed:
Versions:Frequency of
Description:(I'm not sure if the initial Category func_callerid is right, so please move it once the right place is found.)

Whenever there is a 'cidname' database entry submitted with a newline (via php script for example), there's no (incoming) audio on incoming calls originating from that specific callerid via DAHDI (or in earlier versions zaptel).

Acknowledgment: Setting a database entry with a newline at the end is wrong, I agree on this one. I fixed the erroneous code and it's working fine without the newline. But shouldn't asterisk sanitize the input, so that such a crude error doesn't lead to blocked audio at all?

I'm not nearly an expert, but I would guess that the SIP header breaks because of the newline from the database.

Here's a way to reproduce the problem:

PHP Code used to submit the database entry:

$cmd = "database put cidname 12345678 \"Test CID\"\n";
exec('/usr/sbin/asterisk -rx '.escapeshellarg($cmd), $output, $ret);

Entry in the extensions.conf (placed in the context that's receiving incoming ISDN calls, i.e isdn-incoming)

exten => 1234,1,Set(CALLERID(name)=${DB(cidname/${CALLERID(num)})})
exten => 1234,n,Set(CALLERID(num)=00${CALLERID(num)})
exten => 1234,n,Dial(SIP/myphone)
exten => 1234,n,Return

1. Call the php script with a php interpreter in order to add the number to the 'cidname' database.
2. Place a call from the phone with the callerid 12345678
3. Pick up the incoming call on the sip phone identified as "myphone"
4. Notice the missing incoming audio and the

This is how the broken entry looks like:
asterisk*CLI> database show cidname 12345678
/cidname/12345678                                 : Test CID
1 results found.

Notice the empty line after "Test CID".

This is how the cdr-csv/Master.csv entry looks like:
"","12345678","79999999","isdn-incoming","""Test CID
"" <12345678>","DAHDI/4-1","SIP/myphone-0000006f","Dial","SIP/myphone","2010-12-07 13:16:15","2010-12-07 13:16:17","2010-12-07 13:16:26",11,9,"ANSWERED","DOCUMENTATION","1291727775.137",""

There's also a linebreak after "Test CID".

Substitute 12345678 with your incoming caller id (i.e. number of your cellphone). Again, I know setting the "\n" at the end of $cmd is wrong and escapeshellarg() ensures, that it is saved in the cidname database, but again, I think this should be properly sanitized by asterisk so this won't happen.

I stumbled across this bug in 1.2.x already, turning off the functionality without debugging until moving to now. I thought this bug is fixed already so I gave it another try failing again.