Module: kamailio
Branch: 5.5
Commit: 655518a94d413250c4b0246a5e91df7506a5427d
URL:
https://github.com/kamailio/kamailio/commit/655518a94d413250c4b0246a5e91df7…
Author: Daniel-Constantin Mierla <miconda(a)gmail.com>
Committer: Daniel-Constantin Mierla <miconda(a)gmail.com>
Date: 2021-05-26T08:14:33+02:00
core: clone define value to avoid losing the reference
- impacted also by substdef
- GH #2736
(cherry picked from commit 84055b2fe963e01a217149991dd1c8cbe8a8aeec)
---
Modified: src/core/cfg.lex
Modified: src/core/ppcfg.c
Modified: src/core/ppcfg.h
Modified: src/main.c
---
Diff:
https://github.com/kamailio/kamailio/commit/655518a94d413250c4b0246a5e91df7…
Patch:
https://github.com/kamailio/kamailio/commit/655518a94d413250c4b0246a5e91df7…
---
diff --git a/src/core/cfg.lex b/src/core/cfg.lex
index 2b90fbb66a..ff8096d9f2 100644
--- a/src/core/cfg.lex
+++ b/src/core/cfg.lex
@@ -1337,7 +1337,7 @@ IMPORTFILE "import_file"
<DEFINE_DATA>\\{CR} { count(); ksr_cfg_print_part(yytext); } /* eat the escaped CR
*/
<DEFINE_DATA>{CR} { count();
ksr_cfg_print_part(yytext);
- if (pp_define_set(strlen(s_buf.s), s_buf.s)) return 1;
+ if (pp_define_set(strlen(s_buf.s), s_buf.s, KSR_PPDEF_NORMAL)) return 1;
memset(&s_buf, 0, sizeof(s_buf));
state = INITIAL;
ksr_cfg_print_initial_state();
@@ -2007,7 +2007,7 @@ int pp_define(int len, const char *text)
return 0;
}
-int pp_define_set(int len, char *text)
+int pp_define_set(int len, char *text, int mode)
{
int ppos;
@@ -2090,7 +2090,7 @@ int pp_define_env(const char *text, int len)
LM_ERR("cannot set define name [%s]\n", (char*)text);
return -1;
}
- if(pp_define_set(defvalue.len, defvalue.s)<0) {
+ if(pp_define_set(defvalue.len, defvalue.s, KSR_PPDEF_NORMAL)<0) {
LM_ERR("cannot set define value [%s]\n", (char*)text);
return -1;
}
diff --git a/src/core/ppcfg.c b/src/core/ppcfg.c
index 627402ba66..a5aa1d3e28 100644
--- a/src/core/ppcfg.c
+++ b/src/core/ppcfg.c
@@ -143,20 +143,14 @@ int pp_substdef_add(char *data, int mode)
LM_ERR("cannot set define name\n");
goto error;
}
- if(mode==1) {
- /* define the value enclosed in double quotes */
- *(defvalue.s-1) = '"';
- defvalue.s[defvalue.len] = '"';
- defvalue.s--;
- defvalue.len += 2;
- }
if(memchr(defvalue.s, '$', defvalue.len) != NULL) {
fmsg = faked_msg_get_next();
if(pv_eval_str(fmsg, &newval, &defvalue)>=0) {
defvalue = newval;
}
}
- if(pp_define_set(defvalue.len, defvalue.s)<0) {
+ if(pp_define_set(defvalue.len, defvalue.s,
+ (mode==1)?KSR_PPDEF_QUOTED:KSR_PPDEF_NORMAL)<0) {
LM_ERR("cannot set define value\n");
goto error;
}
diff --git a/src/core/ppcfg.h b/src/core/ppcfg.h
index 70627268b6..17b19380bc 100644
--- a/src/core/ppcfg.h
+++ b/src/core/ppcfg.h
@@ -25,6 +25,9 @@
#include "str.h"
+#define KSR_PPDEF_NORMAL (0) /* define normal value */
+#define KSR_PPDEF_QUOTED (1<<0) /* define quoted value */
+
typedef struct ksr_ppdefine {
str name;
str value;
@@ -39,7 +42,7 @@ int pp_substdef_add(char *data, int mode);
int pp_subst_run(char **data);
int pp_define(int len, const char *text);
-int pp_define_set(int len, char *text);
+int pp_define_set(int len, char *text, int mode);
int pp_define_set_type(int type);
str *pp_define_get(int len, const char * text);
int pp_define_env(const char * text, int len);
diff --git a/src/main.c b/src/main.c
index 71a024d5bb..a391f57afb 100644
--- a/src/main.c
+++ b/src/main.c
@@ -2264,7 +2264,7 @@ int main(int argc, char** argv)
}
if(p) {
p++;
- if(pp_define_set(strlen(p), p)<0) {
+ if(pp_define_set(strlen(p), p, KSR_PPDEF_NORMAL)<0) {
fprintf(stderr, "error at define value: -A %s\n",
optarg);
goto error;