diff --git a/res/res_pjsip_authenticator_digest.c b/res/res_pjsip_authenticator_digest.c
index 87b5bfda98de35e2b720239245d959a3a2ea5aad..0a882ecb6a82ddd6e9850256ad8c463cd1bfb95e 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);
+					}
+				}
+			}
 		}
 	}