Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rework contact generation, add validation & enforce contact_user even for requests taking Contact from server_address #3317

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 29 additions & 8 deletions modules/b2b_logic/logic.c
Original file line number Diff line number Diff line change
Expand Up @@ -476,23 +476,43 @@ void b2b_mark_todel( b2bl_tuple_t* tuple)

int b2b_get_local_contact(struct sip_msg *msg, str *from_uri, str *local_contact)
{
struct sip_uri ct_uri;
struct sip_uri ct_uri,server_uri;
const struct socket_info *send_sock = msg ?
(msg->force_send_socket?msg->force_send_socket:msg->rcv.bind_address):NULL;

if (server_address.len) {
if (pv_printf_s(msg, server_address_pve, local_contact) != 0) {
LM_WARN("Failed to print format string from 'server_address'\n");

if (msg) {
get_local_contact(send_sock, NULL, local_contact);
} else {
LM_ERR("No current SIP message, "
"failed to build Contact from send socket\n");
return -1;
goto msg_contact;
} else {
/* validate what we have built */
if (parse_uri(local_contact->s, local_contact->len, &server_uri) < 0) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

parsing the generated URI (based on server_address_pve) is an unnecessary burn - as script writer you need to be sure you configuration is correct and not to expect OpenSIPS to parse it (for each message) just to be sure you are right - eventually you can do a dummy test at startup, to see if the pve generates a valid URI

LM_ERR("Not a valid server sip uri [%.*s]\n", local_contact->len, local_contact->s);
goto msg_contact;
}

/* we have expanded the server address, need to add username, if needed */
if (contact_user) {
send_sock = grep_sock_info( &server_uri.host, server_uri.port_no, server_uri.proto);
if (send_sock == NULL) {
LM_ERR("Failed to find send socket for server address [%.*s]\n", local_contact->len, local_contact->s);
goto msg_contact;
}

memset(&ct_uri, 0, sizeof(struct sip_uri));
if (parse_uri(from_uri->s, from_uri->len, &ct_uri) < 0) {
LM_ERR("Not a valid FROM sip uri [%.*s]\n", from_uri->len, from_uri->s);
goto done;
}

get_local_contact(send_sock, &ct_uri.user, local_contact);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the replacement of the username part (if contact_user is on) in the generated URI (based on server_address_pve) does not look right - you do not actually replace the username part, but build a completely new URI based on the username and socket - so if my server_address_pve was pushing some URI params or anything else, it will be lost. Normally you should have here a sctrict username replacement into the local_contact parsed URI - this may be simply done with 3 memcpy's .

goto done;
} else
/* no contact username needed, we have our valid Contact header based on the server_address */
goto done;
}
} else {
msg_contact:
if (msg) {
memset(&ct_uri, 0, sizeof(struct sip_uri));
if (contact_user && parse_uri(from_uri->s, from_uri->len, &ct_uri) < 0) {
Expand All @@ -507,6 +527,7 @@ int b2b_get_local_contact(struct sip_msg *msg, str *from_uri, str *local_contact
}
}

done:
return 0;
}

Expand Down
Loading