Skip to content

Commit

Permalink
registrar: Add warnings if contact is invalid and REGISTER will be re…
Browse files Browse the repository at this point in the history
…jected

Added some warnings in case a REGISTER is rejected because of an invalid contact header field.
Before, kamailio might answer a 400 Bad Request for a too long contact URI for example without logging any message.

(cherry picked from commit cc0b07d)
  • Loading branch information
AndreasHuber-CH authored and miconda committed Sep 8, 2016
1 parent 8d29d2d commit 2725e74
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions modules/registrar/sip_msg.c
Expand Up @@ -150,12 +150,14 @@ int check_contacts(struct sip_msg* _m, int* _s)
/* The first Contact HF is star */
/* Expires must be zero */
if (get_expires_hf(_m) != 0) {
LM_WARN("expires must be 0 for star contact\n");
rerrno = R_STAR_EXP;
return 1;
}

/* Message must contain no contacts */
if (((contact_body_t*)_m->contact->parsed)->contacts) {
LM_WARN("star contact cannot be mixed with other contacts\n");
rerrno = R_STAR_CONT;
return 1;
}
Expand All @@ -164,6 +166,7 @@ int check_contacts(struct sip_msg* _m, int* _s)
p = _m->contact->next;
while(p) {
if (p->type == HDR_CONTACT_T) {
LM_WARN("star contact cannot be mixed with other contacts\n");
rerrno = R_STAR_CONT;
return 1;
}
Expand All @@ -177,13 +180,19 @@ int check_contacts(struct sip_msg* _m, int* _s)
while(p) {
if (p->type == HDR_CONTACT_T) {
if (((contact_body_t*)p->parsed)->star == 1) {
LM_WARN("star contact cannot be mixed with other contacts\n");
rerrno = R_STAR_CONT;
return 1;
}
/* check also the lenght of all contacts */
/* check also the length of all contacts */
for(c=((contact_body_t*)p->parsed)->contacts ; c ; c=c->next) {
if (c->uri.len > CONTACT_MAX_SIZE
|| (c->received && c->received->len>RECEIVED_MAX_SIZE) ) {
if (c->uri.len > CONTACT_MAX_SIZE) {
LM_WARN("contact uri is too long: [%.*s]\n", c->uri.len, c->uri.s);
rerrno = R_CONTACT_LEN;
return 1;
}
if (c->received && c->received->len>RECEIVED_MAX_SIZE) {
LM_WARN("received attribute of contact is too long\n");
rerrno = R_CONTACT_LEN;
return 1;
}
Expand Down

0 comments on commit 2725e74

Please sign in to comment.