From d4fa7b674f53f1720fb12519461899f97e7dfef7 Mon Sep 17 00:00:00 2001 From: Yalu Zhang <yalu.zhang@iopsys.eu> Date: Fri, 24 Jan 2025 16:32:58 +0000 Subject: [PATCH] Fix a segmentation fault caused by DT syslog with NULL pointer access, REF 16138 Add validation check to prevent NULL pointers from being accessed. --- res/res_pjsip_authenticator_digest.c | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/res/res_pjsip_authenticator_digest.c b/res/res_pjsip_authenticator_digest.c index 87b5bfda98..0a882ecb6a 100644 --- a/res/res_pjsip_authenticator_digest.c +++ b/res/res_pjsip_authenticator_digest.c @@ -415,13 +415,6 @@ static enum ast_sip_check_auth_result digest_check_auth(struct ast_sip_endpoint int is_artificial; int failures = 0; size_t auth_size; - pjsip_sip_uri *client_uri; - pjsip_contact_hdr *contact_hdr; - - contact_hdr = pjsip_msg_find_hdr(rdata->msg_info.msg, PJSIP_H_CONTACT, NULL); - if(contact_hdr){ - client_uri = pjsip_uri_get_uri(contact_hdr->uri); - } auth_size = AST_VECTOR_SIZE(&endpoint->inbound_auths); ast_assert(0 < auth_size); @@ -493,8 +486,17 @@ static enum ast_sip_check_auth_result digest_check_auth(struct ast_sip_endpoint failures++; } if(verify_res[idx] == AUTH_NOAUTH) { - /* lack of auth. IPX003 */ - ast_log_dt(LOG_EVENT_CODE_IPX003, (int) client_uri->user.slen, client_uri->user.ptr, (int) client_uri->host.slen, client_uri->host.ptr); + if (rdata && rdata->msg_info.msg) { + pjsip_contact_hdr *contact_hdr = pjsip_msg_find_hdr(rdata->msg_info.msg, PJSIP_H_CONTACT, NULL); + if (contact_hdr && contact_hdr->uri) { + pjsip_sip_uri *client_uri = pjsip_uri_get_uri(contact_hdr->uri); + if (client_uri) { + /* lack of auth. IPX003 */ + ast_log_dt(LOG_EVENT_CODE_IPX003, (int)client_uri->user.slen, client_uri->user.ptr, + (int)client_uri->host.slen, client_uri->host.ptr); + } + } + } } } -- GitLab