Skip to content

Commit

Permalink
Fix pushing pure INT values into acc extra.
Browse files Browse the repository at this point in the history
Convert integer values to str if the val does not advertise any STR val.
  • Loading branch information
bogdan-iancu committed Feb 13, 2018
1 parent 9924969 commit 46e2dfa
Showing 1 changed file with 19 additions and 11 deletions.
30 changes: 19 additions & 11 deletions modules/acc/acc_vars.c
Expand Up @@ -135,31 +135,39 @@ int pv_get_acc_extra(struct sip_msg *msg, pv_param_t *param,
*/
int set_value_shm(pv_value_t* pvt, extra_value_t* extra)
{
str s;

if (pvt == NULL || pvt->flags&PV_VAL_NULL) {
if (extra->shm_buf_len) {
shm_free(extra->value.s);
extra->shm_buf_len = 0;
}
extra->value.s = NULL;
extra->value.len = 0;
} else if (pvt->flags&PV_TYPE_INT || pvt->flags&PV_VAL_STR) {
} else {
if (pvt->flags&PV_VAL_STR) {
s = pvt->rs;
} else if (pvt->flags&PV_VAL_INT) {
s.s = int2str( pvt->ri, &s.len);
} else {
LM_ERR("invalid pvt value!\n");
return -1;
}

if (extra->shm_buf_len == 0) {
extra->value.s = shm_malloc(pvt->rs.len);
extra->shm_buf_len = extra->value.len = pvt->rs.len;
} else if (extra->shm_buf_len < pvt->rs.len) {
extra->value.s = shm_realloc(extra->value.s, pvt->rs.len);
extra->shm_buf_len = extra->value.len = pvt->rs.len;
extra->value.s = shm_malloc(s.len);
extra->shm_buf_len = extra->value.len = s.len;
} else if (extra->shm_buf_len < s.len) {
extra->value.s = shm_realloc(extra->value.s, s.len);
extra->shm_buf_len = extra->value.len = s.len;
} else {
extra->value.len = pvt->rs.len;
extra->value.len = s.len;
}

if (extra->value.s == NULL)
goto memerr;

memcpy(extra->value.s, pvt->rs.s, pvt->rs.len);
} else {
LM_ERR("invalid pvt value!\n");
return -1;
memcpy(extra->value.s, s.s, s.len);
}

return 0;
Expand Down

0 comments on commit 46e2dfa

Please sign in to comment.