[sr-dev] git:5.3:7e5b726e: core: safety checks for xavp operations
Daniel-Constantin Mierla
miconda at gmail.com
Wed Nov 27 20:31:21 CET 2019
Module: kamailio
Branch: 5.3
Commit: 7e5b726ec106fcc06f9ed406570b3f5fea72bd7e
URL: https://github.com/kamailio/kamailio/commit/7e5b726ec106fcc06f9ed406570b3f5fea72bd7e
Author: Daniel-Constantin Mierla <miconda at gmail.com>
Committer: Daniel-Constantin Mierla <miconda at gmail.com>
Date: 2019-11-27T20:30:17+01:00
core: safety checks for xavp operations
(cherry picked from commit 1067abf87cdaabc9557a99b36ad60e2349e16fa5)
---
Modified: src/core/xavp.c
---
Diff: https://github.com/kamailio/kamailio/commit/7e5b726ec106fcc06f9ed406570b3f5fea72bd7e.diff
Patch: https://github.com/kamailio/kamailio/commit/7e5b726ec106fcc06f9ed406570b3f5fea72bd7e.patch
---
diff --git a/src/core/xavp.c b/src/core/xavp.c
index e5e33f6e9d..7351d830bd 100644
--- a/src/core/xavp.c
+++ b/src/core/xavp.c
@@ -52,6 +52,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);
@@ -69,6 +72,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);
@@ -122,8 +128,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;
@@ -141,8 +148,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);
@@ -172,6 +180,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;
@@ -296,7 +308,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
@@ -333,7 +345,7 @@ sr_xavp_t *xavp_get_next(sr_xavp_t *start)
if(start==NULL)
return NULL;
-
+
avp = start->next;
while(avp)
{
@@ -477,7 +489,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
@@ -529,7 +541,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);
@@ -539,7 +551,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;
@@ -775,6 +787,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))
@@ -840,7 +856,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