Summary:ASTERISK-14210: Parsing of register statements in sip.conf fails when transport is used without extension
Reporter:Olivier Krief (okrief)Labels:
Date Opened:2009-05-27 01:31:43Date Closed:2009-06-19 16:23:10
Versions:Frequency of
Description:In sip.conf, next line works ok
register => trunk4ipbx:passtrunk4ipbx @

Replacing the above line with the one bellow, produces error message printed below
register => udp: //trunk4ipbx:passtrunk4ipbx @

May 26 17:58:42] NOTICE[2859]: chan_sip.c:20169 sip_parse_host: '/' is not a valid port number on line 25 of sip.conf. using default.
[May 26 17:58:42] WARNING[2859]: chan_sip.c:6560 sip_register: Format for registration is [transport ://]user[:secret[:authuser]]@domain[:port][/extension][~expiry] at line 25


Comment in sip_register function in chan_sip.c, says:
Format for registration is [transport: //]user[:secret[:authuser]]@domain[:port][/extension][~expiry]
So, my understanding of this is that "register => udp: //trunk4ipbx:passtrunk4ipbx @<" is valid.

Though, parsing of register statements is done like this:
       /* split [/contact][~expiry] */
       expire = strchr(buf, '~');
       if (expire)
               *expire++ = '\0';
       callback = strrchr(buf, '/');    // Search for latest '/' occurrence
       if (callback)
               *callback++ = '\0';
       if (ast_strlen_zero(callback))
               callback = "s";

       sip_parse_host(buf, lineno, &username, &portnum, &transport);

The trouble is if no /extension is provided but transport is provided in register statement, then buf string is truncated to "udp: /" and not to "udp: //trunk4ipbx:passtrunk4ipbx @". This truncated string is then passed over to sip_parse_host which produces NOTICE message.

My suggestion would be to add a check before "callback = strrchr(buf, '/');" statement but I'm not fluent in C string parsing functions.
Comments:By: Leif Madsen (lmadsen) 2009-06-16 15:58:40

Do you really mean to have a space here?

udp: //

By: Olivier Krief (okrief) 2009-06-16 16:06:24

no, I didn't : I must have "miscopied" my config which is "udp://" without any space.
Could you reproduce this case and get this "sip_parse_host: '/' is not a valid port number" message ?

By: Leif Madsen (lmadsen) 2009-06-16 16:56:50

I didn't attempt to reproduce the issue. Are you getting this on the latest 1.6.1 branch? I know Tilghman put in a change very recently with regards to how the register line was parsed.

By: Olivier Krief (okrief) 2009-06-17 03:32:43

I did no attempt yet with latest 1.6.1 branch.
Anyway, it should be very easy to reproduce this bug for a setup which includes a register statement : add a "udp://" prefix to current register statement and see if you've got the above mentioned error message (no need to create any call).

Would you like me to try with latest 1.6.1 branch or would you prefer to try it yourself ?

By: David Vossel (dvossel) 2009-06-19 16:23:09

issue ASTERISK-14131 resolved this.  update to r201601 in v1.6.1