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 69
 
70 70
 void xavp_free_unsafe(sr_xavp_t *xa)
71 71
 {
72
+	if(xa==NULL) {
73
+		return;
74
+	}
72 75
 	if(xa->val.type == SR_XTYPE_DATA) {
73 76
 		if(xa->val.v.data!=NULL && xa->val.v.data->pfree!=NULL) {
74 77
 			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 122
 
123 123
 int xavp_add(sr_xavp_t *xavp, sr_xavp_t **list)
124 124
 {
125
-	if (xavp==NULL)
125
+	if (xavp==NULL) {
126 126
 		return -1;
127
+	}
127 128
 	/* Prepend new xavp to the list */
128 129
 	if(list) {
129 130
 		xavp->next = *list;
... ...
@@ -141,8 +148,9 @@ int xavp_add_last(sr_xavp_t *xavp, sr_xavp_t **list)
141 141
 	sr_xavp_t *prev;
142 142
 	sr_xavp_t *crt;
143 143
 
144
-	if (xavp==NULL)
144
+	if (xavp==NULL) {
145 145
 		return -1;
146
+	}
146 147
 
147 148
 	crt = xavp_get_internal(&xavp->name, list, 0, 0);
148 149
 
... ...
@@ -172,6 +180,10 @@ int xavp_add_last(sr_xavp_t *xavp, sr_xavp_t **list)
172 172
 
173 173
 int xavp_add_after(sr_xavp_t *nxavp, sr_xavp_t *pxavp)
174 174
 {
175
+	if (nxavp==NULL) {
176
+		return -1;
177
+	}
178
+
175 179
 	if(pxavp==NULL) {
176 180
 		nxavp->next = *_xavp_list_crt;
177 181
 		*_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 296
 	if(name==NULL || name->s==NULL)
297 297
 		return NULL;
298 298
 	id = get_hash1_raw(name->s, name->len);
299
-	
299
+
300 300
 	if(list && *list)
301 301
 		avp = *list;
302 302
 	else
... ...
@@ -333,7 +345,7 @@ sr_xavp_t *xavp_get_next(sr_xavp_t *start)
333 333
 
334 334
 	if(start==NULL)
335 335
 		return NULL;
336
-	
336
+
337 337
 	avp = start->next;
338 338
 	while(avp)
339 339
 	{
... ...
@@ -477,7 +489,7 @@ int xavp_count(str *name, sr_xavp_t **start)
477 477
 	if(name==NULL || name->s==NULL)
478 478
 		return -1;
479 479
 	id = get_hash1_raw(name->s, name->len);
480
-	
480
+
481 481
 	if(start)
482 482
 		avp = *start;
483 483
 	else
... ...
@@ -529,7 +541,7 @@ void xavp_destroy_list(sr_xavp_t **head)
529 529
 void xavp_reset_list(void)
530 530
 {
531 531
 	assert(_xavp_list_crt!=0 );
532
-	
532
+
533 533
 	if (_xavp_list_crt!=&_xavp_list_head)
534 534
 		_xavp_list_crt=&_xavp_list_head;
535 535
 	xavp_destroy_list(_xavp_list_crt);
... ...
@@ -539,7 +551,7 @@ void xavp_reset_list(void)
539 539
 sr_xavp_t **xavp_set_list(sr_xavp_t **head)
540 540
 {
541 541
 	sr_xavp_t **avp;
542
-	
542
+
543 543
 	assert(_xavp_list_crt!=0);
544 544
 
545 545
 	avp = _xavp_list_crt;
... ...
@@ -780,6 +792,10 @@ int xavp_insert(sr_xavp_t *xavp, int idx, sr_xavp_t **list)
780 780
 	int n = 0;
781 781
 	int i = 0;
782 782
 
783
+	if(xavp==NULL) {
784
+		return -1;
785
+	}
786
+
783 787
 	crt = xavp_get_internal(&xavp->name, list, 0, NULL);
784 788
 
785 789
 	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 845
 				avp->next = NULL;
846 846
 			}
847 847
 		}
848
-		
848
+
849 849
 		return avp;
850 850
 	}
851 851