Index: pjproject/trunk/pjsip/src/pjsip-ua/sip_inv.c
===================================================================
--- pjproject/trunk/pjsip/src/pjsip-ua/sip_inv.c	(revision 3189)
+++ pjproject/trunk/pjsip/src/pjsip-ua/sip_inv.c	(revision 3190)
@@ -751,4 +751,5 @@
     pjsip_supported_hdr *sup_hdr;
     pjsip_require_hdr *req_hdr;
+    pjsip_contact_hdr *c_hdr;
     int code = 200;
     unsigned rem_option = 0;
@@ -784,4 +785,25 @@
     /* Init response header list */
     pj_list_init(&res_hdr_list);
+
+    /* Check the Contact header */
+    c_hdr = (pjsip_contact_hdr*)
+	    pjsip_msg_find_hdr(msg, PJSIP_H_CONTACT, NULL);
+    if (!c_hdr || !c_hdr->uri) {
+	/* Missing Contact header or Contact contains "*" */
+	pjsip_warning_hdr *w;
+	pj_str_t warn_text;
+
+	warn_text = pj_str("Bad/missing Contact header");
+	w = pjsip_warning_hdr_create(rdata->tp_info.pool, 399,
+				     pjsip_endpt_name(endpt),
+				     &warn_text);
+	if (w) {
+	    pj_list_push_back(&res_hdr_list, w);
+	}
+
+	code = PJSIP_SC_BAD_REQUEST;
+	status = PJSIP_ERRNO_FROM_SIP_STATUS(code);
+	goto on_return;
+    }
 
     /* Check the request body, see if it's something that we support,
Index: pjproject/trunk/pjsip/src/pjsip/sip_dialog.c
===================================================================
--- pjproject/trunk/pjsip/src/pjsip/sip_dialog.c	(revision 3189)
+++ pjproject/trunk/pjsip/src/pjsip/sip_dialog.c	(revision 3190)
@@ -433,6 +433,7 @@
 				         pos);
 	if (contact_hdr) {
-	    if (!PJSIP_URI_SCHEME_IS_SIP(contact_hdr->uri) && 
-		!PJSIP_URI_SCHEME_IS_SIPS(contact_hdr->uri))
+	    if (!contact_hdr->uri ||
+		(!PJSIP_URI_SCHEME_IS_SIP(contact_hdr->uri) &&
+		 !PJSIP_URI_SCHEME_IS_SIPS(contact_hdr->uri)))
 	    {
 		pos = (pjsip_hdr*)contact_hdr->next;
@@ -612,5 +613,5 @@
     contact = (const pjsip_contact_hdr*)
 	      pjsip_msg_find_hdr(msg, PJSIP_H_CONTACT, NULL);
-    if (contact == NULL)
+    if (contact == NULL || contact->uri == NULL)
 	return PJSIP_EMISSINGHDR;
 
@@ -1502,5 +1503,5 @@
 
 
-/* This function is called by user agent upon receiving incoming response
+/* This function is called by user agent upon receiving incoming request
  * message.
  */
@@ -1589,8 +1590,9 @@
 		  pjsip_msg_find_hdr(rdata->msg_info.msg, PJSIP_H_CONTACT, 
 				     NULL);
-	if (contact && (dlg->remote.contact==NULL ||
-			pjsip_uri_cmp(PJSIP_URI_IN_REQ_URI, 
-				      dlg->remote.contact->uri, 
-				      contact->uri)))
+	if (contact && contact->uri &&
+	    (dlg->remote.contact==NULL ||
+ 	     pjsip_uri_cmp(PJSIP_URI_IN_REQ_URI,
+			   dlg->remote.contact->uri,
+			   contact->uri)))
 	{
 	    dlg->remote.contact = (pjsip_contact_hdr*) 
@@ -1794,8 +1796,9 @@
 		  pjsip_msg_find_hdr(rdata->msg_info.msg, PJSIP_H_CONTACT, 
 				     NULL);
-	if (contact && (dlg->remote.contact==NULL ||
-			pjsip_uri_cmp(PJSIP_URI_IN_REQ_URI, 
-				      dlg->remote.contact->uri, 
-				      contact->uri)))
+	if (contact && contact->uri &&
+	    (dlg->remote.contact==NULL ||
+	     pjsip_uri_cmp(PJSIP_URI_IN_REQ_URI,
+			   dlg->remote.contact->uri,
+			   contact->uri)))
 	{
 	    dlg->remote.contact = (pjsip_contact_hdr*) 
@@ -1844,8 +1847,9 @@
 							  PJSIP_H_CONTACT, 
 				     			  NULL);
-	if (contact && (dlg->remote.contact==NULL ||
-			pjsip_uri_cmp(PJSIP_URI_IN_REQ_URI, 
-				      dlg->remote.contact->uri, 
-				      contact->uri)))
+	if (contact && contact->uri &&
+	    (dlg->remote.contact==NULL ||
+	     pjsip_uri_cmp(PJSIP_URI_IN_REQ_URI,
+			   dlg->remote.contact->uri,
+			   contact->uri)))
 	{
 	    dlg->remote.contact = (pjsip_contact_hdr*) 
Index: pjproject/trunk/pjsip/src/pjsua-lib/pjsua_acc.c
===================================================================
--- pjproject/trunk/pjsip/src/pjsua-lib/pjsua_acc.c	(revision 3189)
+++ pjproject/trunk/pjsip/src/pjsua-lib/pjsua_acc.c	(revision 3190)
@@ -2238,7 +2238,10 @@
 					   pos);
 	    if (h_contact) {
-		uri = (pjsip_uri*) pjsip_uri_get_uri(h_contact->uri);
-		if (!PJSIP_URI_SCHEME_IS_SIP(uri) && 
-		    !PJSIP_URI_SCHEME_IS_SIPS(uri))
+		if (h_contact->uri)
+		    uri = (pjsip_uri*) pjsip_uri_get_uri(h_contact->uri);
+		else
+		    uri = NULL;
+		if (!uri || (!PJSIP_URI_SCHEME_IS_SIP(uri) &&
+		             !PJSIP_URI_SCHEME_IS_SIPS(uri)))
 		{
 		    pos = (pjsip_hdr*)h_contact->next;
Index: pjproject/trunk/pjsip/src/pjsua-lib/pjsua_im.c
===================================================================
--- pjproject/trunk/pjsip/src/pjsua-lib/pjsua_im.c	(revision 3189)
+++ pjproject/trunk/pjsip/src/pjsua-lib/pjsua_im.c	(revision 3190)
@@ -170,5 +170,5 @@
 		  pjsip_msg_find_hdr(rdata->msg_info.msg, PJSIP_H_CONTACT,
 				     NULL);
-    if (contact_hdr) {
+    if (contact_hdr && contact_hdr->uri) {
 	contact.ptr = (char*) pj_pool_alloc(rdata->tp_info.pool, 
 				    	    PJSIP_MAX_URL_SIZE);
Index: pjproject/trunk/pjsip/src/pjsua-lib/pjsua_pres.c
===================================================================
--- pjproject/trunk/pjsip/src/pjsua-lib/pjsua_pres.c	(revision 3189)
+++ pjproject/trunk/pjsip/src/pjsua-lib/pjsua_pres.c	(revision 3190)
@@ -1611,5 +1611,5 @@
 		  pjsip_msg_find_hdr(event->body.rx_msg.rdata->msg_info.msg,
 				     PJSIP_H_CONTACT, NULL);
-    if (!contact_hdr) {
+    if (!contact_hdr || !contact_hdr->uri) {
 	return;
     }
