Skip to content

Commit 224a323

Browse files
committed
dialog: do not populate dst_leg on unmatched dlg
Avoid chaning the dst_leg on unmatched dialogs, as this might lead to inconsistent states. A common pattern is to match a dialog in state 5, which would set a dst_leg, but then "invalidate" the dialog due to the bad state - proceeding to a next dialog would not set the dst_leg (as it was set by the previous match), leading to an invalid access in the second dialog. Credits go to NFON for reporting and providing valuable troubleshooting information
1 parent 195a186 commit 224a323

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

modules/dialog/dlg_hash.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -819,6 +819,7 @@ struct dlg_cell* get_dlg( str *callid, str *ftag, str *ttag,
819819
struct dlg_cell *dlg;
820820
struct dlg_entry *d_entry;
821821
unsigned int h_entry;
822+
unsigned int dst_leg_backup = *dst_leg;
822823

823824
h_entry = dlg_hash(callid);
824825
d_entry = &(d_table->entries[h_entry]);
@@ -844,12 +845,16 @@ struct dlg_cell* get_dlg( str *callid, str *ftag, str *ttag,
844845
dlg->legs[DLG_CALLER_LEG].contact.len);
845846
#endif
846847
if (match_dialog( dlg, callid, ftag, ttag, dir, dst_leg)==1) {
847-
if (dlg->state==DLG_STATE_DELETED)
848+
if (dlg->state==DLG_STATE_DELETED) {
848849
/* even if matched, skip the deleted dialogs as they may be
849850
a previous unsuccessful attempt of established call
850851
with the same callid and fromtag - like in auth/challenge
851852
case -bogdan */
853+
/* since this dialog is not considered matched, then the
854+
* dst_leg should not be populated either */
855+
*dst_leg = dst_leg_backup;
852856
continue;
857+
}
853858
DBG_REF(dlg, 1);
854859
dlg->ref++;
855860
dlg_unlock( d_table, d_entry);

0 commit comments

Comments
 (0)