-
Notifications
You must be signed in to change notification settings - Fork 782
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
Clone sdp in sip timer to prevent modification #2476
Conversation
The patch looks okay, but perhaps there is a catch. Without the patch, app modifies With the patch, app will modify the clone, so the modification won't be seen by SDP negotiator and later Here is an alternative approach. Currently |
I've tested the new fix in Asterisk and it worked. I'm fairly new to the internals of pjsip, so please forgive if that is a stupid/obvious question, but what guarantees that the transmit data pool of the outgoing INVITE (i.e., the one that was used to allocate the modified SDP value) is still in-use/untouched when the SDP is cloned in process_answer()? From an Asterisk standpoint it would not matter if the original SDP (my version of patch) or the already modified SDP (current version) is used for the >= 2. refresh INVITEs, either works. |
The pool being used in process_answer() is passed as a parameter, so the function caller needs to make sure that the pool is still valid. In PJSIP, the passed pool is usually call inv's pool, so it should be valid for the duration of the call. |
Good question actually. Just rechecked things, currently the transaction will maintain the last transmitted data ( |
I'm not concerned about that pool but about the one that is used to modify the SDP in Asterisk, i.e. |
For a practical check (just to be extra careful, not that I doubt your analysis), I instrumented pjsip and Asterisk with some log statements to trace the cloning and releasing of the pool in question. Although the two operations happen on different threads, the release always happened after the clone, even when a delay of up to 1 second was introduced with
I thought about that too, but I do not think that is an option in Asterisk. Thank you all for your help. |
PJSIP, UDP transport with external_media_address and session timers enabled. Connected to SIP server that is not in local net. Asterisk initiated the connection and is refreshing the session after 150s (timeout 300s). The 2nd refresh-INVITE triggered by the pjsip timer has a malformed IP address in its SDP (garbage string). This only happens when the SDP is modified by the nat-code to replace the local IP address with the configured external_media_address. Analysis: the code to modify the SDP (in res_pjsip_session.c:session_outgoing_nat_hook() and also (redundantly?) in res_pjsip_sdp_rtp.c:change_outgoing_sdp_stream_media_address()) uses the tdata->pool to allocate the replacement string. But the same pjmedia_sdp_stream that was modified for the 1st refresh-INVITE is also used for the 2nd refresh-INVITE (because it is stored in pjmedia's pjmedia_sdp_neg structure). The problem is, that at that moment, the tdata->pool that holds the stringified external_media_address from the 1. refresh-INVITE has long been reused for something else. Fix by Sauw Ming of pjproject (see pjsip/pjproject#2476): the local, potentially modified pjmedia_sdp_stream is cloned in pjproject/source/pjsip/src/pjmedia/sip_neg.c:process_answer() and the clone is stored, thereby detaching from the tdata->pool (which is only released *after* process_answer()) ASTERISK-28973 Reported-by: Michael Neuhauser Change-Id: I272ac22436076596e06aa51b9fa23fd1c7734a0e
PJSIP, UDP transport with external_media_address and session timers enabled. Connected to SIP server that is not in local net. Asterisk initiated the connection and is refreshing the session after 150s (timeout 300s). The 2nd refresh-INVITE triggered by the pjsip timer has a malformed IP address in its SDP (garbage string). This only happens when the SDP is modified by the nat-code to replace the local IP address with the configured external_media_address. Analysis: the code to modify the SDP (in res_pjsip_session.c:session_outgoing_nat_hook() and also (redundantly?) in res_pjsip_sdp_rtp.c:change_outgoing_sdp_stream_media_address()) uses the tdata->pool to allocate the replacement string. But the same pjmedia_sdp_stream that was modified for the 1st refresh-INVITE is also used for the 2nd refresh-INVITE (because it is stored in pjmedia's pjmedia_sdp_neg structure). The problem is, that at that moment, the tdata->pool that holds the stringified external_media_address from the 1. refresh-INVITE has long been reused for something else. Fix by Sauw Ming of pjproject (see pjsip/pjproject#2476): the local, potentially modified pjmedia_sdp_stream is cloned in pjproject/source/pjsip/src/pjmedia/sip_neg.c:process_answer() and the clone is stored, thereby detaching from the tdata->pool (which is only released *after* process_answer()) ASTERISK-28973 Reported-by: Michael Neuhauser Change-Id: I272ac22436076596e06aa51b9fa23fd1c7734a0e
PJSIP, UDP transport with external_media_address and session timers enabled. Connected to SIP server that is not in local net. Asterisk initiated the connection and is refreshing the session after 150s (timeout 300s). The 2nd refresh-INVITE triggered by the pjsip timer has a malformed IP address in its SDP (garbage string). This only happens when the SDP is modified by the nat-code to replace the local IP address with the configured external_media_address. Analysis: the code to modify the SDP (in res_pjsip_session.c:session_outgoing_nat_hook() and also (redundantly?) in res_pjsip_sdp_rtp.c:change_outgoing_sdp_stream_media_address()) uses the tdata->pool to allocate the replacement string. But the same pjmedia_sdp_stream that was modified for the 1st refresh-INVITE is also used for the 2nd refresh-INVITE (because it is stored in pjmedia's pjmedia_sdp_neg structure). The problem is, that at that moment, the tdata->pool that holds the stringified external_media_address from the 1. refresh-INVITE has long been reused for something else. Fix by Sauw Ming of pjproject (see pjsip/pjproject#2476): the local, potentially modified pjmedia_sdp_stream is cloned in pjproject/source/pjsip/src/pjmedia/sip_neg.c:process_answer() and the clone is stored, thereby detaching from the tdata->pool (which is only released *after* process_answer()) ASTERISK-28973 Reported-by: Michael Neuhauser Change-Id: I272ac22436076596e06aa51b9fa23fd1c7734a0e
PJSIP, UDP transport with external_media_address and session timers enabled. Connected to SIP server that is not in local net. Asterisk initiated the connection and is refreshing the session after 150s (timeout 300s). The 2nd refresh-INVITE triggered by the pjsip timer has a malformed IP address in its SDP (garbage string). This only happens when the SDP is modified by the nat-code to replace the local IP address with the configured external_media_address. Analysis: the code to modify the SDP (in res_pjsip_session.c:session_outgoing_nat_hook() and also (redundantly?) in res_pjsip_sdp_rtp.c:change_outgoing_sdp_stream_media_address()) uses the tdata->pool to allocate the replacement string. But the same pjmedia_sdp_stream that was modified for the 1st refresh-INVITE is also used for the 2nd refresh-INVITE (because it is stored in pjmedia's pjmedia_sdp_neg structure). The problem is, that at that moment, the tdata->pool that holds the stringified external_media_address from the 1. refresh-INVITE has long been reused for something else. Fix by Sauw Ming of pjproject (see pjsip/pjproject#2476): the local, potentially modified pjmedia_sdp_stream is cloned in pjproject/source/pjsip/src/pjmedia/sip_neg.c:process_answer() and the clone is stored, thereby detaching from the tdata->pool (which is only released *after* process_answer()) ASTERISK-28973 Reported-by: Michael Neuhauser Change-Id: I272ac22436076596e06aa51b9fa23fd1c7734a0e
PJSIP, UDP transport with external_media_address and session timers enabled. Connected to SIP server that is not in local net. Asterisk initiated the connection and is refreshing the session after 150s (timeout 300s). The 2nd refresh-INVITE triggered by the pjsip timer has a malformed IP address in its SDP (garbage string). This only happens when the SDP is modified by the nat-code to replace the local IP address with the configured external_media_address. Analysis: the code to modify the SDP (in res_pjsip_session.c:session_outgoing_nat_hook() and also (redundantly?) in res_pjsip_sdp_rtp.c:change_outgoing_sdp_stream_media_address()) uses the tdata->pool to allocate the replacement string. But the same pjmedia_sdp_stream that was modified for the 1st refresh-INVITE is also used for the 2nd refresh-INVITE (because it is stored in pjmedia's pjmedia_sdp_neg structure). The problem is, that at that moment, the tdata->pool that holds the stringified external_media_address from the 1. refresh-INVITE has long been reused for something else. Fix by Sauw Ming of pjproject (see pjsip/pjproject#2476): the local, potentially modified pjmedia_sdp_stream is cloned in pjproject/source/pjsip/src/pjmedia/sip_neg.c:process_answer() and the clone is stored, thereby detaching from the tdata->pool (which is only released *after* process_answer()) ASTERISK-28973 Reported-by: Michael Neuhauser Change-Id: I272ac22436076596e06aa51b9fa23fd1c7734a0e
Fixed #2475.
The patch in this PR is proposed by the creator of the issue above, @mneuhauser.