@@ -1576,7 +1576,7 @@ enum sip_validation_failures {
15761576 SV_BAD_USERNAME = -27 ,
15771577 SV_FROM_USERNAME_ERROR = -28 ,
15781578 SV_TO_USERNAME_ERROR = -29 ,
1579- SV_BAD_EXPIRES = -30 ,
1579+ SV_BAD_STAR_CONTACT = -30 ,
15801580 SV_GENERIC_FAILURE = -255
15811581};
15821582
@@ -1621,24 +1621,39 @@ static enum sip_validation_failures validate_contact_header(struct sip_msg *msg,
16211621 /* empty contacts header - this can be a * Contact header, valid only for REGISTER requests */
16221622 contact_body = (contact_body_t * ) msg -> contact -> parsed ;
16231623
1624- if (method != METHOD_REGISTER || msg -> first_line .type == SIP_REPLY ) {
1625- strcpy (reason , "empty body for 'Contact' header" );
1626- ret = SV_CONTACT_PARSE_ERROR ;
1627- goto failed ;
1628- } else {
1624+ if (method == METHOD_REGISTER ) {
1625+ if (contact_body -> star != 1 ) {
1626+ strcpy (reason , "empty body for 'Contact' header" );
1627+ ret = SV_CONTACT_PARSE_ERROR ;
1628+ goto failed ;
1629+ } else if (msg -> first_line .type == SIP_REPLY ) {
1630+ strcpy (reason , "Contact header for REGISTER reply contains '*' only valid for REGISTER request" );
1631+ ret = SV_BAD_STAR_CONTACT ;
1632+ goto failed ;
1633+ }
1634+
16291635 if (!msg -> expires || (parse_expires (msg -> expires ) < 0 || !msg -> expires -> parsed )) {
16301636 strcpy (reason , "failed to parse 'Expires' header" );
1631- ret = SV_BAD_EXPIRES ;
1637+ ret = SV_BAD_STAR_CONTACT ;
16321638 goto failed ;
16331639 }
16341640
16351641 expires_body = (exp_body_t * ) msg -> expires -> parsed ;
16361642
1637- if (!expires_body || !( expires_body -> val == 0 && contact_body -> star == 1 ) ) {
1643+ if (!expires_body || expires_body -> val != 0 ) {
16381644 strcpy (reason , "Expires header greater than 0 for REGISTER 'Contact' header with '*' value" );
1639- ret = SV_CONTACT_PARSE_ERROR ;
1645+ ret = SV_BAD_STAR_CONTACT ;
16401646 goto failed ;
16411647 }
1648+ } else {
1649+ if (contact_body -> star != 1 ) {
1650+ strcpy (reason , "empty body for 'Contact' header" );
1651+ ret = SV_CONTACT_PARSE_ERROR ;
1652+ } else {
1653+ strcpy (reason , "Contact header for SIP message contains '*' only valid for REGISTER request" );
1654+ ret = SV_BAD_STAR_CONTACT ;
1655+ }
1656+ goto failed ;
16421657 }
16431658 }
16441659 }
@@ -1894,7 +1909,7 @@ static int w_sip_validate(struct sip_msg *msg, void *_flags, pv_spec_t* err_txt)
18941909 }
18951910 }
18961911
1897- if (flags & SIP_PARSE_CONTACT && (status_code > 199 || status_code < 400 )) {
1912+ if (flags & SIP_PARSE_CONTACT && (status_code > 199 && status_code < 400 )) {
18981913 ret = validate_contact_header (msg , method , reason );
18991914
19001915 if (ret != 0 ) {
0 commit comments