[sr-dev] git:5.2:ca4d105c: core: safety checks for xavp operations

Daniel-Constantin Mierla miconda at gmail.com
Wed Nov 27 20:33:49 CET 2019


Module: kamailio
Branch: 5.2
Commit: ca4d105c8b9718138e0d6a62b81cdf2d63470712
URL: https://github.com/kamailio/kamailio/commit/ca4d105c8b9718138e0d6a62b81cdf2d63470712

Author: Daniel-Constantin Mierla <miconda at gmail.com>
Committer: Daniel-Constantin Mierla <miconda at gmail.com>
Date: 2019-11-27T20:33:11+01:00

core: safety checks for xavp operations

(cherry picked from commit 1067abf87cdaabc9557a99b36ad60e2349e16fa5)
(cherry picked from commit 7e5b726ec106fcc06f9ed406570b3f5fea72bd7e)

---

Modified: src/core/xavp.c

---

Diff:  https://github.com/kamailio/kamailio/commit/ca4d105c8b9718138e0d6a62b81cdf2d63470712.diff
Patch: https://github.com/kamailio/kamailio/commit/ca4d105c8b9718138e0d6a62b81cdf2d63470712.patch

---

diff --git a/src/core/xavp.c b/src/core/xavp.c
index c758a98099..44ab3ac3ed 100644
--- a/src/core/xavp.c
+++ b/src/core/xavp.c
@@ -54,6 +54,9 @@ void xavp_shm_free_unsafe(void *p)
 
 void xavp_free(sr_xavp_t *xa)
 {
+	if(xa==NULL) {
+		return;
+	}
 	if(xa->val.type == SR_XTYPE_DATA) {
 		if(xa->val.v.data!=NULL && xa->val.v.data->pfree!=NULL) {
 			xa->val.v.data->pfree(xa->val.v.data->p, xavp_shm_free);
@@ -67,6 +70,9 @@ void xavp_free(sr_xavp_t *xa)
 
 void xavp_free_unsafe(sr_xavp_t *xa)
 {
+	if(xa==NULL) {
+		return;
+	}
 	if(xa->val.type == SR_XTYPE_DATA) {
 		if(xa->val.v.data!=NULL && xa->val.v.data->pfree!=NULL) {
 			xa->val.v.data->pfree(xa->val.v.data->p, xavp_shm_free_unsafe);
@@ -114,8 +120,9 @@ static sr_xavp_t *xavp_new_value(str *name, sr_xval_t *val)
 
 int xavp_add(sr_xavp_t *xavp, sr_xavp_t **list)
 {
-	if (xavp==NULL)
+	if (xavp==NULL) {
 		return -1;
+	}
 	/* Prepend new xavp to the list */
 	if(list) {
 		xavp->next = *list;
@@ -133,8 +140,9 @@ int xavp_add_last(sr_xavp_t *xavp, sr_xavp_t **list)
 	sr_xavp_t *prev;
 	sr_xavp_t *crt;
 
-	if (xavp==NULL)
+	if (xavp==NULL) {
 		return -1;
+	}
 
 	crt = xavp_get_internal(&xavp->name, list, 0, 0);
 
@@ -164,6 +172,10 @@ int xavp_add_last(sr_xavp_t *xavp, sr_xavp_t **list)
 
 int xavp_add_after(sr_xavp_t *nxavp, sr_xavp_t *pxavp)
 {
+	if (nxavp==NULL) {
+		return -1;
+	}
+
 	if(pxavp==NULL) {
 		nxavp->next = *_xavp_list_crt;
 		*_xavp_list_crt = nxavp;
@@ -288,7 +300,7 @@ static sr_xavp_t *xavp_get_internal(str *name, sr_xavp_t **list, int idx, sr_xav
 	if(name==NULL || name->s==NULL)
 		return NULL;
 	id = get_hash1_raw(name->s, name->len);
-	
+
 	if(list && *list)
 		avp = *list;
 	else
@@ -325,7 +337,7 @@ sr_xavp_t *xavp_get_next(sr_xavp_t *start)
 
 	if(start==NULL)
 		return NULL;
-	
+
 	avp = start->next;
 	while(avp)
 	{
@@ -455,7 +467,7 @@ int xavp_count(str *name, sr_xavp_t **start)
 	if(name==NULL || name->s==NULL)
 		return -1;
 	id = get_hash1_raw(name->s, name->len);
-	
+
 	if(start)
 		avp = *start;
 	else
@@ -507,7 +519,7 @@ void xavp_destroy_list(sr_xavp_t **head)
 void xavp_reset_list(void)
 {
 	assert(_xavp_list_crt!=0 );
-	
+
 	if (_xavp_list_crt!=&_xavp_list_head)
 		_xavp_list_crt=&_xavp_list_head;
 	xavp_destroy_list(_xavp_list_crt);
@@ -517,7 +529,7 @@ void xavp_reset_list(void)
 sr_xavp_t **xavp_set_list(sr_xavp_t **head)
 {
 	sr_xavp_t **avp;
-	
+
 	assert(_xavp_list_crt!=0);
 
 	avp = _xavp_list_crt;
@@ -749,6 +761,10 @@ int xavp_insert(sr_xavp_t *xavp, int idx, sr_xavp_t **list)
 	int n = 0;
 	int i = 0;
 
+	if(xavp==NULL) {
+		return -1;
+	}
+
 	crt = xavp_get_internal(&xavp->name, list, 0, NULL);
 
 	if (idx == 0 && (!crt || crt->val.type != SR_XTYPE_NULL))
@@ -814,7 +830,7 @@ sr_xavp_t *xavp_extract(str *name, sr_xavp_t **list)
 				avp->next = NULL;
 			}
 		}
-		
+
 		return avp;
 	}
 




More information about the sr-dev mailing list