From 016cfe1b6abe8e96f4bf0b27ed9ed422267bc3ad Mon Sep 17 00:00:00 2001 From: Ilkka Nurlund Date: Mon, 10 Apr 2023 06:36:04 +0000 Subject: [PATCH 1/2] nta.c/leg_find: Fix 'by method' leg matching condition In certain cases 'leg_method' might be null so the IF statement: if (leg_method && method_name && !su_casematch(method_name, leg_method)) continue; is not working at all despite 'method_name' is not null. It leads to leg matching process returns false positive at: if (loose_match == NULL) loose_match = leg; --- libsofia-sip-ua/nta/nta.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libsofia-sip-ua/nta/nta.c b/libsofia-sip-ua/nta/nta.c index e360b7ed..f0ad0539 100644 --- a/libsofia-sip-ua/nta/nta.c +++ b/libsofia-sip-ua/nta/nta.c @@ -5120,7 +5120,7 @@ nta_leg_t *leg_find(nta_agent_t const *sa, if (leg_url && request_uri && url_cmp(leg_url, request_uri)) continue; - if (leg_method && method_name && !su_casematch(method_name, leg_method)) + if (leg_method == NULL || method_name && !su_casematch(method_name, leg_method)) continue; /* Perfect match if both local and To have tag From 6cf8d6a6e2fb3d7fa10657fd9b9d63017093bce1 Mon Sep 17 00:00:00 2001 From: Ilkka Nurlund Date: Mon, 10 Apr 2023 08:13:22 +0000 Subject: [PATCH 2/2] nta.c/incoming_find: Fix "Merged Request" case matching /RFC3261 8.2.2.2; 17.2.3/ Implements missing matching rules (17.2.3.1 and 17.2.3.2) --- libsofia-sip-ua/nta/nta.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/libsofia-sip-ua/nta/nta.c b/libsofia-sip-ua/nta/nta.c index f0ad0539..d6d4d748 100644 --- a/libsofia-sip-ua/nta/nta.c +++ b/libsofia-sip-ua/nta/nta.c @@ -6238,10 +6238,16 @@ static nta_incoming_t *incoming_find(nta_agent_t const *agent, /* RFC3261 - section 8.2.2.2 Merged Requests */ if (return_merge) { - if (irq->irq_cseq->cs_method == cseq->cs_method && - strcmp(irq->irq_cseq->cs_method_name, - cseq->cs_method_name) == 0) - *return_merge = irq, return_merge = NULL; + /* RFC3261 - section 17.2.3 Matching Requests to Server Transactions */ + if (irq->irq_via->v_branch && + su_casematch(irq->irq_via->v_branch, v->v_branch) && + su_casematch(irq->irq_via->v_host, v->v_host) && + su_strmatch(irq->irq_via->v_port, v->v_port)) { + if (irq->irq_cseq->cs_method == cseq->cs_method && + strcmp(irq->irq_cseq->cs_method_name, + cseq->cs_method_name) == 0) + *return_merge = irq, return_merge = NULL; + } } }