Summary:ASTERISK-07253: [patch] Parsing fails if From header contains angle brackets
Reporter:Ben Smithurst (bsmithurst)Labels:
Date Opened:2006-06-29 10:54:05Date Closed:2006-11-18 12:07:36.000-0600
Versions:Frequency of
Environment:Attachments:( 0) bad_trace.txt
( 1) get_callerid_patch.txt
( 2) good_trace.txt
Description:The get_calleridname function incorrectly parses headers that contain angle brackets.  For example at our company our logo looks like <gradwell> so some of our staff have e.g. <gradwell> Support as their SIP phone display name.

This is then sent as something like

From: "<gradwell> Support" <sip:blah@whatever.gradwell.net>

When this is then sent out to another server, Asterisk has incorrectly parsed it, and sends out something like

From: """ <sip:blah@whatever.gradwell.net>

That's three angle brackets - it found the name as just being the quote before the first angle brackets, and then surrounded it with two more angle brackets.

Unfortunately I don't have any exact traces stored, however it is easily reproducible and the above headers fairly accurately describe what happens.

The attached patch appears to fix this problem, I have tested it with display names like

foo <bar>
<foo> bar
foo <bar> baz

and it has not had any problems parsing them.
Comments:By: Ben Smithurst (bsmithurst) 2006-06-29 10:54:37

sorry - the second trace is of course 3 double quotes, not three angle brackets as I said...

By: Serge Vecher (serge-v) 2006-06-29 14:18:53

bsmithurst: thanks for the contribution. This will need a disclaimer to be reviewed. Can you please get a disclaimer on file http://bugs.digium.com/main_page.php and confirm when done?

Also, if you don't mind, please turn sip debug on and attach a console grab here of a failing situation, and corrected one with this patch. Thanks.

By: Ben Smithurst (bsmithurst) 2006-06-30 03:44:01

vechers: I have attached the SIP traces now, and will try to get the disclaimer faxed off later today.

By: Ben Smithurst (bsmithurst) 2006-06-30 04:05:44

The disclaimer has been faxed off now.

By: jmls (jmls) 2006-10-31 12:08:03.000-0600

can we confirm that the disclaimer was received ?
Patch still seems to apply to trunk

By: Luigi Rizzo (rizzo) 2006-11-13 11:34:49.000-0600

apart from comments, i think the real fix is this change to
function get_calleridname()

-       if (tmp && tmp < end) {
+       if (tmp && tmp <= end) {

You were just hitting a corner case where the < was just after the " and
the code got it wrong. The other part of your patch is just dealing with
escaped quotes \" in the string, i'd handle that with a separate function
strchr2(base, char, escape) which skips escaped characters.
Olle, let me know if i should commit this.

By: Olle Johansson (oej) 2006-11-13 13:17:07.000-0600

rizzo - go ahead.

By: Olle Johansson (oej) 2006-11-18 03:48:32.000-0600

rizzo: If you have fixed this, add the revision number and close the bug as fixed. THanks.

By: Luigi Rizzo (rizzo) 2006-11-18 12:07:35.000-0600

fixed in both trunk and 1.4, not with the proposed patch
but with simpler code.