Module: kamailio
Branch: 5.5
Commit: 65249c184f5fd54b3ea16edbda518ac7ff442d86
URL:
https://github.com/kamailio/kamailio/commit/65249c184f5fd54b3ea16edbda518ac…
Author: Daniel-Constantin Mierla <miconda(a)gmail.com>
Committer: Daniel-Constantin Mierla <miconda(a)gmail.com>
Date: 2021-07-12T15:34:42+02:00
core: fix building quoted value for #!subsdefs
(cherry picked from commit 879f8c4e52ab7f7f489107f18e2c80795c788bdd)
---
Modified: src/core/cfg.lex
Modified: src/core/cfg.y
Modified: src/core/ppcfg.c
Modified: src/main.c
---
Diff:
https://github.com/kamailio/kamailio/commit/65249c184f5fd54b3ea16edbda518ac…
Patch:
https://github.com/kamailio/kamailio/commit/65249c184f5fd54b3ea16edbda518ac…
---
diff --git a/src/core/cfg.lex b/src/core/cfg.lex
index ff8096d9f2..a6115a7599 100644
--- a/src/core/cfg.lex
+++ b/src/core/cfg.lex
@@ -2049,11 +2049,12 @@ int pp_define_set(int len, char *text, int mode)
pp_defines[ppos].value.len = len;
pp_defines[ppos].value.s = text;
- LM_DBG("### setting define ID [%.*s] value [%.*s]\n",
+ LM_DBG("### setting define ID [%.*s] value [%.*s] (mode: %d)\n",
pp_defines[ppos].name.len,
pp_defines[ppos].name.s,
pp_defines[ppos].value.len,
- pp_defines[ppos].value.s);
+ pp_defines[ppos].value.s,
+ mode);
return 0;
}
diff --git a/src/core/cfg.y b/src/core/cfg.y
index be0a664dce..5b205fd230 100644
--- a/src/core/cfg.y
+++ b/src/core/cfg.y
@@ -2213,9 +2213,9 @@ event_route_stm:
preprocess_stm:
SUBST STRING { if(pp_subst_add($2)<0) YYERROR; }
| SUBST error { yyerror("invalid subst preprocess statement"); }
- | SUBSTDEF STRING { if(pp_substdef_add($2, 0)<0) YYERROR; }
+ | SUBSTDEF STRING { if(pp_substdef_add($2, KSR_PPDEF_NORMAL)<0) YYERROR; }
| SUBSTDEF error { yyerror("invalid substdef preprocess statement"); }
- | SUBSTDEFS STRING { if(pp_substdef_add($2, 1)<0) YYERROR; }
+ | SUBSTDEFS STRING { if(pp_substdef_add($2, KSR_PPDEF_QUOTED)<0) YYERROR; }
| SUBSTDEFS error { yyerror("invalid substdefs preprocess statement"); }
;
diff --git a/src/core/ppcfg.c b/src/core/ppcfg.c
index 73c0a2ef3c..67391557f8 100644
--- a/src/core/ppcfg.c
+++ b/src/core/ppcfg.c
@@ -30,6 +30,7 @@
#include "ut.h"
#include "re.h"
#include "pvar.h"
+#include "pvapi.h"
#include "str_list.h"
#include "dprint.h"
@@ -149,25 +150,40 @@ int pp_substdef_add(char *data, int mode)
if(memchr(defvalue.s, '$', defvalue.len) != NULL) {
fmsg = faked_msg_get_next();
if(pv_eval_str(fmsg, &newval, &defvalue)>=0) {
- sb = str_list_block_add(&_ksr_substdef_strlist, newval.s, newval.len);
- if(sb==NULL) {
- LM_ERR("failed to handle substdef: [%s]\n", data);
- return -1;
+ if(mode!=KSR_PPDEF_QUOTED) {
+ sb = str_list_block_add(&_ksr_substdef_strlist, newval.s, newval.len);
+ if(sb==NULL) {
+ LM_ERR("failed to handle substdef: [%s]\n", data);
+ return -1;
+ }
+ defvalue = sb->s;
+ } else {
+ defvalue = newval;
}
- defvalue = sb->s;
}
}
- if(pp_define_set(defvalue.len, defvalue.s,
- (mode==1)?KSR_PPDEF_QUOTED:KSR_PPDEF_NORMAL)<0) {
+ if(mode==KSR_PPDEF_QUOTED) {
+ if(pv_get_buffer_size() < defvalue.len + 4) {
+ LM_ERR("defined value is too large\n");
+ return -1;
+ }
+ newval.s = pv_get_buffer();
+ newval.s[0] = '"';
+ memcpy(newval.s + 1, defvalue.s, defvalue.len);
+ newval.s[defvalue.len + 1] = '"';
+ newval.s[defvalue.len + 2] = '\0';
+ newval.len = defvalue.len + 2;
+ sb = str_list_block_add(&_ksr_substdef_strlist, newval.s, newval.len);
+ if(sb==NULL) {
+ LM_ERR("failed to handle substdef: [%s]\n", data);
+ return -1;
+ }
+ defvalue = sb->s;
+ }
+ if(pp_define_set(defvalue.len, defvalue.s, KSR_PPDEF_QUOTED)<0) {
LM_ERR("cannot set define value\n");
goto error;
}
- if(mode==1) {
- defvalue.s++;
- defvalue.len -= 2;
- *(defvalue.s-1) = c;
- defvalue.s[defvalue.len] = c;
- }
LM_DBG("### added substdef: [%.*s]=[%.*s] (%d)\n", defname.len, defname.s,
defvalue.len, defvalue.s, mode);
diff --git a/src/main.c b/src/main.c
index a391f57afb..7630fcfeff 100644
--- a/src/main.c
+++ b/src/main.c
@@ -2330,7 +2330,7 @@ int main(int argc, char** argv)
fprintf(stderr, "bad substdef parameter\n");
goto error;
}
- if(pp_substdef_add(optarg, 0)<0) {
+ if(pp_substdef_add(optarg, KSR_PPDEF_NORMAL)<0) {
LM_ERR("failed to add substdef expression: %s\n", optarg);
goto error;
}
@@ -2340,7 +2340,7 @@ int main(int argc, char** argv)
fprintf(stderr, "bad substdefs parameter\n");
goto error;
}
- if(pp_substdef_add(optarg, 1)<0) {
+ if(pp_substdef_add(optarg, KSR_PPDEF_QUOTED)<0) {
LM_ERR("failed to add substdefs expression: %s\n", optarg);
goto error;
}