mirror of
https://github.com/asterisk/asterisk.git
synced 2025-09-03 11:25:35 +00:00
AST-2020-001 - res_pjsip: Return dialog locked and referenced
pjproject returns the dialog locked and with a reference. However,
in Asterisk the method that handles this decrements the reference
and removes the lock prior to returning. This makes it possible,
under some circumstances, for another thread to free said dialog
before the thread that created it attempts to use it again. Of
course when the thread that created it tries to use a freed dialog
a crash can occur.
This patch makes it so Asterisk now returns the newly created
dialog both locked, and with an added reference. This allows the
caller to de-reference, and unlock the dialog when it is safe to
do so.
In the case of a new SIP Invite the lock, and reference are now
held for the entirety of the new invite handling process.
Otherwise it's possible for the dialog, or its dependent objects,
like the transaction, to disappear. For example if there is a TCP
transport error.
ASTERISK-29057 #close
Change-Id: I5ef645a47829596f402cf383dc02c629c618969e
(cherry picked from commit 6baa4b53be
)
This commit is contained in:
committed by
George Joseph
parent
cd8f8b94f8
commit
b82f880647
@@ -2003,12 +2003,55 @@ pjsip_dialog *ast_sip_create_dialog_uac(const struct ast_sip_endpoint *endpoint,
|
||||
/*!
|
||||
* \brief General purpose method for creating a UAS dialog with an endpoint
|
||||
*
|
||||
* \deprecated This function is unsafe (due to the returned object not being locked nor
|
||||
* having its reference incremented) and should no longer be used. Instead
|
||||
* use ast_sip_create_dialog_uas_locked so a properly locked and referenced
|
||||
* object is returned.
|
||||
*
|
||||
* \param endpoint A pointer to the endpoint
|
||||
* \param rdata The request that is starting the dialog
|
||||
* \param[out] status On failure, the reason for failure in creating the dialog
|
||||
*/
|
||||
pjsip_dialog *ast_sip_create_dialog_uas(const struct ast_sip_endpoint *endpoint, pjsip_rx_data *rdata, pj_status_t *status);
|
||||
|
||||
/*!
|
||||
* \brief General purpose method for creating a UAS dialog with an endpoint
|
||||
*
|
||||
* This function creates and returns a locked, and referenced counted pjsip
|
||||
* dialog object. The caller is thus responsible for freeing the allocated
|
||||
* memory, decrementing the reference, and releasing the lock when done with
|
||||
* the returned object.
|
||||
*
|
||||
* \note The safest way to unlock the object, and decrement its reference is by
|
||||
* calling pjsip_dlg_dec_lock. Alternatively, pjsip_dlg_dec_session can be
|
||||
* used to decrement the reference only.
|
||||
*
|
||||
* The dialog is returned locked and with a reference in order to ensure that the
|
||||
* dialog object, and any of its associated objects (e.g. transaction) are not
|
||||
* untimely destroyed. For instance, that could happen when a transport error
|
||||
* occurs.
|
||||
*
|
||||
* As long as the caller maintains a reference to the dialog there should be no
|
||||
* worry that it might unknowningly be destroyed. However, once the caller unlocks
|
||||
* the dialog there is a danger that some of the dialog's internal objects could
|
||||
* be lost and/or compromised. For example, when the aforementioned transport error
|
||||
* occurs the dialog's associated transaction gets destroyed (see pjsip_dlg_on_tsx_state
|
||||
* in sip_dialog.c, and mod_inv_on_tsx_state in sip_inv.c).
|
||||
*
|
||||
* In this case and before using the dialog again the caller should re-lock the
|
||||
* dialog, check to make sure the dialog is still established, and the transaction
|
||||
* still exists and has not been destroyed.
|
||||
*
|
||||
* \param endpoint A pointer to the endpoint
|
||||
* \param rdata The request that is starting the dialog
|
||||
* \param[out] status On failure, the reason for failure in creating the dialog
|
||||
*
|
||||
* \retval A locked, and reference counted pjsip_dialog object.
|
||||
* \retval NULL on failure
|
||||
*/
|
||||
pjsip_dialog *ast_sip_create_dialog_uas_locked(const struct ast_sip_endpoint *endpoint,
|
||||
pjsip_rx_data *rdata, pj_status_t *status);
|
||||
|
||||
/*!
|
||||
* \brief General purpose method for creating an rdata structure using specific information
|
||||
* \since 13.15.0
|
||||
|
Reference in New Issue
Block a user