Module: kamailio
Branch: master
Commit: 54905e6b02e36e72bb74a92c77b273cf57822f18
URL:
https://github.com/kamailio/kamailio/commit/54905e6b02e36e72bb74a92c77b273c…
Author: Daniel-Constantin Mierla <miconda(a)gmail.com>
Committer: Daniel-Constantin Mierla <miconda(a)gmail.com>
Date: 2022-08-31T10:18:07+02:00
acc: duplicate dlg var values used in extra2strar_dlg_only()
- avoid buffer index overlapping and be coherent with extra2strar()
---
Modified: src/modules/acc/acc_cdr.c
Modified: src/modules/acc/acc_extra.c
---
Diff:
https://github.com/kamailio/kamailio/commit/54905e6b02e36e72bb74a92c77b273c…
Patch:
https://github.com/kamailio/kamailio/commit/54905e6b02e36e72bb74a92c77b273c…
---
diff --git a/src/modules/acc/acc_cdr.c b/src/modules/acc/acc_cdr.c
index b54e3a37cef..d3009c85383 100644
--- a/src/modules/acc/acc_cdr.c
+++ b/src/modules/acc/acc_cdr.c
@@ -227,12 +227,13 @@ static int db_write_cdr( struct dlg_cell* dialog,
m += n;
} else if (cdr_expired_dlg_enable){
LM_WARN( "fallback to dlg_only search because of message doesn't
exist.\n");
- m += extra2strar_dlg_only( cdr_extra,
+ n += extra2strar_dlg_only( cdr_extra,
dialog,
cdr_value_array + m,
cdr_int_array + m,
cdr_type_array +m,
&dlgb);
+ m += n;
}
for( ; i<m; i++) {
@@ -311,7 +312,7 @@ static int log_write_cdr( struct dlg_cell* dialog,
cdr_type_array + message_index);
} else if (cdr_expired_dlg_enable){
LM_DBG("fallback to dlg_only search because of message does not exist.\n");
- message_index += extra2strar_dlg_only( cdr_extra,
+ extra_index += extra2strar_dlg_only( cdr_extra,
dialog,
cdr_value_array + message_index,
cdr_int_array + message_index,
diff --git a/src/modules/acc/acc_extra.c b/src/modules/acc/acc_extra.c
index 5c29cc7a047..01fbcb9c82b 100644
--- a/src/modules/acc/acc_extra.c
+++ b/src/modules/acc/acc_extra.c
@@ -268,6 +268,7 @@ int extra2strar_dlg_only(struct acc_extra *extra, struct dlg_cell*
dlg, str *val
//string value;
str* value = 0;
int n=0;
+ int i;
if( !dlg || !val_arr || !int_arr || !type_arr || !p_dlgb)
{
@@ -297,7 +298,22 @@ int extra2strar_dlg_only(struct acc_extra *extra, struct dlg_cell*
dlg, str *val
if (value)
{
- val_arr[n].s = value->s;
+ val_arr[n].s = (char *)pkg_malloc(value->len + 1);
+ if (val_arr[n].s == NULL ) {
+ PKG_MEM_ERROR;
+ /* cleanup already allocated memory and
+ * return that we didn't do anything */
+ for (i = 0; i < n ; i++) {
+ if (NULL != val_arr[i].s){
+ pkg_free(val_arr[i].s);
+ val_arr[i].s = NULL;
+ }
+ }
+ n = 0;
+ goto done;
+ }
+ memcpy(val_arr[n].s, value->s, value->len);
+ val_arr[n].s[value->len] = '\0';
val_arr[n].len = value->len;
type_arr[n] = TYPE_STR;
}