Browse code

core: safety checks for xavp operations

Daniel-Constantin Mierla authored on 27/11/2019 19:28:49
Showing 1 changed files
... ...
@@ -52,6 +52,9 @@ void xavp_shm_free_unsafe(void *p)
52 52
 
53 53
 void xavp_free(sr_xavp_t *xa)
54 54
 {
55
+	if(xa==NULL) {
56
+		return;
57
+	}
55 58
 	if(xa->val.type == SR_XTYPE_DATA) {
56 59
 		if(xa->val.v.data!=NULL && xa->val.v.data->pfree!=NULL) {
57 60
 			xa->val.v.data->pfree(xa->val.v.data->p, xavp_shm_free);
... ...
@@ -69,6 +72,9 @@ void xavp_free(sr_xavp_t *xa)
69 72
 
70 73
 void xavp_free_unsafe(sr_xavp_t *xa)
71 74
 {
75
+	if(xa==NULL) {
76
+		return;
77
+	}
72 78
 	if(xa->val.type == SR_XTYPE_DATA) {
73 79
 		if(xa->val.v.data!=NULL && xa->val.v.data->pfree!=NULL) {
74 80
 			xa->val.v.data->pfree(xa->val.v.data->p, xavp_shm_free_unsafe);
... ...
@@ -122,8 +128,9 @@ static sr_xavp_t *xavp_new_value(str *name, sr_xval_t *val)
122 128
 
123 129
 int xavp_add(sr_xavp_t *xavp, sr_xavp_t **list)
124 130
 {
125
-	if (xavp==NULL)
131
+	if (xavp==NULL) {
126 132
 		return -1;
133
+	}
127 134
 	/* Prepend new xavp to the list */
128 135
 	if(list) {
129 136
 		xavp->next = *list;
... ...
@@ -141,8 +148,9 @@ int xavp_add_last(sr_xavp_t *xavp, sr_xavp_t **list)
141 148
 	sr_xavp_t *prev;
142 149
 	sr_xavp_t *crt;
143 150
 
144
-	if (xavp==NULL)
151
+	if (xavp==NULL) {
145 152
 		return -1;
153
+	}
146 154
 
147 155
 	crt = xavp_get_internal(&xavp->name, list, 0, 0);
148 156
 
... ...
@@ -172,6 +180,10 @@ int xavp_add_last(sr_xavp_t *xavp, sr_xavp_t **list)
172 180
 
173 181
 int xavp_add_after(sr_xavp_t *nxavp, sr_xavp_t *pxavp)
174 182
 {
183
+	if (nxavp==NULL) {
184
+		return -1;
185
+	}
186
+
175 187
 	if(pxavp==NULL) {
176 188
 		nxavp->next = *_xavp_list_crt;
177 189
 		*_xavp_list_crt = nxavp;
... ...
@@ -296,7 +308,7 @@ static sr_xavp_t *xavp_get_internal(str *name, sr_xavp_t **list, int idx, sr_xav
296 308
 	if(name==NULL || name->s==NULL)
297 309
 		return NULL;
298 310
 	id = get_hash1_raw(name->s, name->len);
299
-	
311
+
300 312
 	if(list && *list)
301 313
 		avp = *list;
302 314
 	else
... ...
@@ -333,7 +345,7 @@ sr_xavp_t *xavp_get_next(sr_xavp_t *start)
333 345
 
334 346
 	if(start==NULL)
335 347
 		return NULL;
336
-	
348
+
337 349
 	avp = start->next;
338 350
 	while(avp)
339 351
 	{
... ...
@@ -477,7 +489,7 @@ int xavp_count(str *name, sr_xavp_t **start)
477 489
 	if(name==NULL || name->s==NULL)
478 490
 		return -1;
479 491
 	id = get_hash1_raw(name->s, name->len);
480
-	
492
+
481 493
 	if(start)
482 494
 		avp = *start;
483 495
 	else
... ...
@@ -529,7 +541,7 @@ void xavp_destroy_list(sr_xavp_t **head)
529 541
 void xavp_reset_list(void)
530 542
 {
531 543
 	assert(_xavp_list_crt!=0 );
532
-	
544
+
533 545
 	if (_xavp_list_crt!=&_xavp_list_head)
534 546
 		_xavp_list_crt=&_xavp_list_head;
535 547
 	xavp_destroy_list(_xavp_list_crt);
... ...
@@ -539,7 +551,7 @@ void xavp_reset_list(void)
539 551
 sr_xavp_t **xavp_set_list(sr_xavp_t **head)
540 552
 {
541 553
 	sr_xavp_t **avp;
542
-	
554
+
543 555
 	assert(_xavp_list_crt!=0);
544 556
 
545 557
 	avp = _xavp_list_crt;
... ...
@@ -780,6 +792,10 @@ int xavp_insert(sr_xavp_t *xavp, int idx, sr_xavp_t **list)
780 792
 	int n = 0;
781 793
 	int i = 0;
782 794
 
795
+	if(xavp==NULL) {
796
+		return -1;
797
+	}
798
+
783 799
 	crt = xavp_get_internal(&xavp->name, list, 0, NULL);
784 800
 
785 801
 	if (idx == 0 && (!crt || crt->val.type != SR_XTYPE_NULL))
... ...
@@ -845,7 +861,7 @@ sr_xavp_t *xavp_extract(str *name, sr_xavp_t **list)
845 861
 				avp->next = NULL;
846 862
 			}
847 863
 		}
848
-		
864
+
849 865
 		return avp;
850 866
 	}
851 867