diff --git a/modules/stir_shaken/stir_shaken.c b/modules/stir_shaken/stir_shaken.c index 21cbeb77bbd..cf7bbc60fbf 100644 --- a/modules/stir_shaken/stir_shaken.c +++ b/modules/stir_shaken/stir_shaken.c @@ -848,6 +848,20 @@ static int build_unsigned_pport(str *buf, time_t iat_ts, str *attest, return -1; } +/* RFC 4904 allows telephone-related parameters (tgrp, trunk-context, ...) to + * be carried as semicolon-separated fields inside the userinfo part of a + * SIP/TEL URI (before the '@'). parse_uri() returns the whole userinfo in the + * .user field, so a value such as "+33123456789;tgrp=...;trunk-context=..." + * would otherwise fail the E.164 check. Keep only the leading telephone + * number by trimming at the first ';'. */ +static inline void trim_tn_params(str *tn) +{ + char *semi = q_memchr(tn->s, ';', tn->len); + + if (semi) + tn->len = semi - tn->s; +} + static int get_orig_tn_from_msg(struct sip_msg *msg, str *orig_tn) { struct to_body *body; @@ -889,6 +903,7 @@ static int get_orig_tn_from_msg(struct sip_msg *msg, str *orig_tn) } *orig_tn = parsed_uri.user; + trim_tn_params(orig_tn); return 0; } @@ -920,6 +935,7 @@ static int get_dest_tn_from_msg(struct sip_msg *msg, str *dest_tn) } *dest_tn = parsed_uri.user; + trim_tn_params(dest_tn); return 0; }