pjsip_parse_uri() fails with '@' in URI parameter

BW
Brian White
Thu, Apr 6, 2017 11:52 PM

Hello,

We're running into problems with pjsip being unable to parse a SIP URI with
a '@' character in URI parameters.

FWIW reproduction code (tested with 2.5.5 and 2.6):

#include <pjsip.h>

int main(int argc, char** argv) {
if (argc < 2) {
fprintf(stderr, "Missing URI\n");
return 1;
}

pj_init();

pj_caching_pool cp;
pj_caching_pool_init(&cp, &pj_pool_factory_default_policy, 0);
pj_pool_t* pool = pj_pool_create(
&cp.factory, // pool factory
"test",      // pool name
4096,        // init size
512,        // increment size
NULL        // callback on error
);

pjsip_endpoint* endpt;
pjsip_endpt_create(&cp.factory, "test", &endpt);

char* uri = argv[1];
printf("Trying to parse (%d): %s\n", strlen(uri), uri);
pjsip_uri* parsed_uri = pjsip_parse_uri(pool, uri, strlen(uri),
PJSIP_PARSE_URI_AS_NAMEADDR);
if (parsed_uri)
printf("success\n");
else
printf("failure\n");
return 0;
}

A call to this program like this will print 'success': ./pjsip-bug '<
sip:123@192.168.1.1>'

A call to this program like this will print 'failure': ./pjsip-bug '<
sip:123@192.168.1.1;foo;bar=baz@quux>'

Currently our workaround consists of replacing all '@' characters with '_'
just so that we can actually parse the URI, because (fortunately) we
currently do not utilize the parameters in which these characters tend to
occur in. However, we would like a better (more relaxed parsing) solution
from pjsip in case other restricted characters are sent in URI parameters.
Is such a (feasible) solution already possible?

Hello, We're running into problems with pjsip being unable to parse a SIP URI with a '@' character in URI parameters. FWIW reproduction code (tested with 2.5.5 and 2.6): #include <pjsip.h> int main(int argc, char** argv) { if (argc < 2) { fprintf(stderr, "Missing URI\n"); return 1; } pj_init(); pj_caching_pool cp; pj_caching_pool_init(&cp, &pj_pool_factory_default_policy, 0); pj_pool_t* pool = pj_pool_create( &cp.factory, // pool factory "test", // pool name 4096, // init size 512, // increment size NULL // callback on error ); pjsip_endpoint* endpt; pjsip_endpt_create(&cp.factory, "test", &endpt); char* uri = argv[1]; printf("Trying to parse (%d): %s\n", strlen(uri), uri); pjsip_uri* parsed_uri = pjsip_parse_uri(pool, uri, strlen(uri), PJSIP_PARSE_URI_AS_NAMEADDR); if (parsed_uri) printf("success\n"); else printf("failure\n"); return 0; } A call to this program like this will print 'success': ./pjsip-bug '< sip:123@192.168.1.1>' A call to this program like this will print 'failure': ./pjsip-bug '< sip:123@192.168.1.1;foo;bar=baz@quux>' Currently our workaround consists of replacing all '@' characters with '_' just so that we can actually parse the URI, because (fortunately) we currently do not utilize the parameters in which these characters tend to occur in. However, we would like a better (more relaxed parsing) solution from pjsip in case other restricted characters are sent in URI parameters. Is such a (feasible) solution already possible?
ZT
Zoltan.Toth.ext@rohde-schwarz.com
Fri, Apr 7, 2017 7:26 AM

Hi Brian,

'@' is not an allowed character in URI parameter values so I see no PJSIP
bug here. IMO you need to have the UA that sends these URIs fixed. If it
is not possible, you could try escaping the @ characters (replace them
with %40 instead of _) before passing the URIs to the parser - thus you
don't lose the information.

Cheers,
Zoltan

PS. From https://tools.ietf.org/html/rfc3261#section-25.1

uri-parameter    =  transport-param / user-param / method-param
/ ttl-param / maddr-param / lr-param / other-param
other-param      =  pname [ "=" pvalue ]
pvalue            =  1paramchar
paramchar        =  param-unreserved / unreserved / escaped
param-unreserved  =  "[" / "]" / "/" / ":" / "&" / "+" / "$"
unreserved        =  alphanum / mark
mark        =  "-" / "_" / "." / "!" / "~" / "
" / "'"
/ "(" / ")"
escaped    =  "%" HEXDIG HEXDIG

Von:    Brian White mscdex@mscdex.net
An:    pjsip@lists.pjsip.org
Datum:  07.04.2017 01:53
Betreff:        [Newsletter] [pjsip] pjsip_parse_uri() fails with '@' in
URI parameter
Gesendet von:  "pjsip" pjsip-bounces@lists.pjsip.org

Hello,

We're running into problems with pjsip being unable to parse a SIP URI
with a '@' character in URI parameters.

FWIW reproduction code (tested with 2.5.5 and 2.6):

#include <pjsip.h>

int main(int argc, char** argv) {
if (argc < 2) {
fprintf(stderr, "Missing URI\n");
return 1;
}

pj_init();

pj_caching_pool cp;
pj_caching_pool_init(&cp, &pj_pool_factory_default_policy, 0);
pj_pool_t* pool = pj_pool_create(
&cp.factory, // pool factory
"test",      // pool name
4096,        // init size
512,        // increment size
NULL        // callback on error
);

pjsip_endpoint* endpt;
pjsip_endpt_create(&cp.factory, "test", &endpt);

char* uri = argv[1];
printf("Trying to parse (%d): %s\n", strlen(uri), uri);
pjsip_uri* parsed_uri = pjsip_parse_uri(pool, uri, strlen(uri),
PJSIP_PARSE_URI_AS_NAMEADDR);
if (parsed_uri)
printf("success\n");
else
printf("failure\n");
return 0;
}

A call to this program like this will print 'success': ./pjsip-bug '<
sip:123@192.168.1.1>'

A call to this program like this will print 'failure': ./pjsip-bug '<
sip:123@192.168.1.1;foo;bar=baz@quux>'

Currently our workaround consists of replacing all '@' characters with '_'
just so that we can actually parse the URI, because (fortunately) we
currently do not utilize the parameters in which these characters tend to
occur in. However, we would like a better (more relaxed parsing) solution
from pjsip in case other restricted characters are sent in URI parameters.
Is such a (feasible) solution already possible?


Visit our blog: http://blog.pjsip.org

pjsip mailing list
pjsip@lists.pjsip.org
http://lists.pjsip.org/mailman/listinfo/pjsip_lists.pjsip.org

Hi Brian, '@' is not an allowed character in URI parameter values so I see no PJSIP bug here. IMO you need to have the UA that sends these URIs fixed. If it is not possible, you could try escaping the @ characters (replace them with %40 instead of _) before passing the URIs to the parser - thus you don't lose the information. Cheers, Zoltan PS. From https://tools.ietf.org/html/rfc3261#section-25.1 uri-parameter = transport-param / user-param / method-param / ttl-param / maddr-param / lr-param / other-param other-param = pname [ "=" pvalue ] pvalue = 1*paramchar paramchar = param-unreserved / unreserved / escaped param-unreserved = "[" / "]" / "/" / ":" / "&" / "+" / "$" unreserved = alphanum / mark mark = "-" / "_" / "." / "!" / "~" / "*" / "'" / "(" / ")" escaped = "%" HEXDIG HEXDIG Von: Brian White <mscdex@mscdex.net> An: pjsip@lists.pjsip.org Datum: 07.04.2017 01:53 Betreff: [Newsletter] [pjsip] pjsip_parse_uri() fails with '@' in URI parameter Gesendet von: "pjsip" <pjsip-bounces@lists.pjsip.org> Hello, We're running into problems with pjsip being unable to parse a SIP URI with a '@' character in URI parameters. FWIW reproduction code (tested with 2.5.5 and 2.6): #include <pjsip.h> int main(int argc, char** argv) { if (argc < 2) { fprintf(stderr, "Missing URI\n"); return 1; } pj_init(); pj_caching_pool cp; pj_caching_pool_init(&cp, &pj_pool_factory_default_policy, 0); pj_pool_t* pool = pj_pool_create( &cp.factory, // pool factory "test", // pool name 4096, // init size 512, // increment size NULL // callback on error ); pjsip_endpoint* endpt; pjsip_endpt_create(&cp.factory, "test", &endpt); char* uri = argv[1]; printf("Trying to parse (%d): %s\n", strlen(uri), uri); pjsip_uri* parsed_uri = pjsip_parse_uri(pool, uri, strlen(uri), PJSIP_PARSE_URI_AS_NAMEADDR); if (parsed_uri) printf("success\n"); else printf("failure\n"); return 0; } A call to this program like this will print 'success': ./pjsip-bug '< sip:123@192.168.1.1>' A call to this program like this will print 'failure': ./pjsip-bug '< sip:123@192.168.1.1;foo;bar=baz@quux>' Currently our workaround consists of replacing all '@' characters with '_' just so that we can actually parse the URI, because (fortunately) we currently do not utilize the parameters in which these characters tend to occur in. However, we would like a better (more relaxed parsing) solution from pjsip in case other restricted characters are sent in URI parameters. Is such a (feasible) solution already possible? _______________________________________________ Visit our blog: http://blog.pjsip.org pjsip mailing list pjsip@lists.pjsip.org http://lists.pjsip.org/mailman/listinfo/pjsip_lists.pjsip.org