Skip to content

Commit

Permalink
htable: safety check for item name value
Browse files Browse the repository at this point in the history
(cherry picked from commit 0dbf086)
  • Loading branch information
miconda committed Jan 29, 2020
1 parent 0e366f1 commit 0864bad
Showing 1 changed file with 35 additions and 1 deletion.
36 changes: 35 additions & 1 deletion src/modules/htable/ht_api.c
Expand Up @@ -237,6 +237,10 @@ ht_t* ht_get_table(str *name)
unsigned int htid;
ht_t *ht;

if(name==NULL || name->s==NULL) {
LM_WARN("invalid name parameter\n");
return NULL;
}
htid = ht_compute_hash(name);

/* does it exist */
Expand All @@ -263,6 +267,10 @@ int ht_add_table(str *name, int autoexp, str *dbtable, str *dbcols, int size,
int c;
int i;

if(name==NULL || name->s==NULL) {
LM_WARN("invalid name parameter\n");
return -1;
}
htid = ht_compute_hash(name);

/* does it exist */
Expand Down Expand Up @@ -463,8 +471,14 @@ int ht_set_cell_ex(ht_t *ht, str *name, int type, int_str *val, int mode,
ht_cell_t *it, *prev, *cell;
time_t now;

if(ht==NULL || ht->entries==NULL)
if(ht==NULL || ht->entries==NULL) {
LM_WARN("invalid ht parameter\n");
return -1;
}
if(name==NULL || name->s==NULL) {
LM_WARN("invalid name parameter\n");
return -1;
}

hid = ht_compute_hash(name);

Expand Down Expand Up @@ -639,6 +653,10 @@ int ht_del_cell(ht_t *ht, str *name)
if(ht==NULL || ht->entries==NULL)
return -1;

if(name==NULL || name->s==NULL) {
LM_WARN("invalid name parameter\n");
return -1;
}
hid = ht_compute_hash(name);

idx = ht_get_entry(hid, ht->htsize);
Expand Down Expand Up @@ -685,6 +703,10 @@ ht_cell_t* ht_cell_value_add(ht_t *ht, str *name, int val, ht_cell_t *old)
if(ht==NULL || ht->entries==NULL)
return NULL;

if(name==NULL || name->s==NULL) {
LM_WARN("invalid name parameter\n");
return NULL;
}
hid = ht_compute_hash(name);

idx = ht_get_entry(hid, ht->htsize);
Expand Down Expand Up @@ -807,6 +829,10 @@ ht_cell_t* ht_cell_pkg_copy(ht_t *ht, str *name, ht_cell_t *old)
if(ht==NULL || ht->entries==NULL)
return NULL;

if(name==NULL || name->s==NULL) {
LM_WARN("invalid name parameter\n");
return NULL;
}
hid = ht_compute_hash(name);

idx = ht_get_entry(hid, ht->htsize);
Expand Down Expand Up @@ -1157,6 +1183,10 @@ int ht_set_cell_expire(ht_t *ht, str *name, int type, int_str *val)
if(ht->htexpire==0)
return 0;

if(name==NULL || name->s==NULL) {
LM_WARN("invalid name parameter\n");
return -1;
}
hid = ht_compute_hash(name);

idx = ht_get_entry(hid, ht->htsize);
Expand Down Expand Up @@ -1202,6 +1232,10 @@ int ht_get_cell_expire(ht_t *ht, str *name, unsigned int *val)
if(ht->htexpire==0)
return 0;

if(name==NULL || name->s==NULL) {
LM_WARN("invalid name parameter\n");
return -1;
}
hid = ht_compute_hash(name);

idx = ht_get_entry(hid, ht->htsize);
Expand Down

0 comments on commit 0864bad

Please sign in to comment.