Skip to content

Commit 1872243

Browse files
Marcel Heckomarcel
authored andcommitted
Fix #40: Prevent segfault from NULL via_p1 in transaction matching
Add comprehensive NULL checks to prevent segmentation faults when matching SIP transactions with corrupted or invalid state: 1. compare_branch(): Check t, t->msg, and t->msg->via_p1 before access 2. match_reply(): Add NULL check for stored transaction's msg and via_p1 The crash occurred when iterating through stored transactions and attempting to match branch parameters. While the incoming message's via_p1 is validated by assertion, stored transactions could have NULL via_p1 due to memory corruption, parser edge cases, or race conditions. Changes from original fix: - Also protect match_reply() which had the same vulnerability - Check t->msg before t->msg->via_p1 to prevent cascading NULL deref - Use ERROR instead of WARN (indicates serious bug condition) - Add diagnostic pointer values to log message Fixes: #40
1 parent 6e113db commit 1872243

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

core/sip/trans_table.cpp

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,13 @@ trans_bucket::~trans_bucket()
6161
static inline bool compare_branch(sip_trans* t, sip_msg* msg,
6262
const char* branch, unsigned int branch_len)
6363
{
64+
if(!t || !t->msg || !t->msg->via_p1) {
65+
ERROR("BUG: Invalid transaction in compare_branch (t=%p, msg=%p, via_p1=%p)\n",
66+
(void*)t, t ? (void*)t->msg : NULL,
67+
(t && t->msg) ? (void*)t->msg->via_p1 : NULL);
68+
return false;
69+
}
70+
6471
if(t->msg->via_p1->branch.len != branch_len + MAGIC_BRANCH_LEN)
6572
return false;
6673

@@ -287,11 +294,17 @@ sip_trans* trans_bucket::match_reply(sip_msg* msg)
287294

288295
trans_list::iterator it = elmts.begin();
289296
for(;it!=elmts.end();++it) {
290-
297+
291298
if((*it)->type != TT_UAC){
292299
continue;
293300
}
294301

302+
// Defensive NULL check - should never happen but prevents crash
303+
if(!(*it)->msg || !(*it)->msg->via_p1) {
304+
ERROR("BUG: Invalid transaction in match_reply\n");
305+
continue;
306+
}
307+
295308
if((*it)->msg->via_p1->branch.len != msg->via_p1->branch.len)
296309
continue;
297310

0 commit comments

Comments
 (0)