Module: kamailio
Branch: master
Commit: 9c239dc385716255b977d8d879946e707e6f51c3
URL:
https://github.com/kamailio/kamailio/commit/9c239dc385716255b977d8d879946e7…
Author: Daniel-Constantin Mierla <miconda(a)gmail.com>
Committer: Daniel-Constantin Mierla <miconda(a)gmail.com>
Date: 2021-04-05T17:50:31+02:00
core: checks for trying to define empty or null ids
- use found pointer to compute the lenght of ID for -A parameter to save
a strlen()
---
Modified: src/core/cfg.lex
Modified: src/main.c
---
Diff:
https://github.com/kamailio/kamailio/commit/9c239dc385716255b977d8d879946e7…
Patch:
https://github.com/kamailio/kamailio/commit/9c239dc385716255b977d8d879946e7…
---
diff --git a/src/core/cfg.lex b/src/core/cfg.lex
index b8e4f9aa70..d36fc72b54 100644
--- a/src/core/cfg.lex
+++ b/src/core/cfg.lex
@@ -1927,11 +1927,16 @@ ksr_ppdefine_t* pp_get_define(int idx)
return &pp_defines[idx];
}
-static int pp_lookup(int len, const char * text)
+static int pp_lookup(int len, const char *text)
{
str var = {(char *)text, len};
int i;
+ if(len<=0 || text==NULL) {
+ LM_ERR("invalid parameters");
+ return -1;
+ }
+
for (i=0; i<pp_num_defines; i++)
if (STR_EQ(pp_defines[i].name, var))
return i;
@@ -1945,10 +1950,15 @@ int pp_define_set_type(int type)
return 0;
}
-int pp_define(int len, const char * text)
+int pp_define(int len, const char *text)
{
int ppos;
+ if(len<=0 || text==NULL) {
+ LM_ERR("invalid parameters");
+ return -1;
+ }
+
LM_DBG("defining id: %.*s\n", len, text);
if (pp_num_defines == MAX_DEFINES) {
@@ -2010,7 +2020,7 @@ int pp_define_set(int len, char *text)
LM_BUG("BUG: the index in define table not set yet\n");
return -1;
}
- if(len<=0) {
+ if(len<=0 || text==NULL) {
LM_DBG("no define value - ignoring\n");
return 0;
}
@@ -2046,7 +2056,7 @@ int pp_define_set(int len, char *text)
return 0;
}
-int pp_define_env(const char * text, int len)
+int pp_define_env(const char *text, int len)
{
char *r;
str defname;
@@ -2087,7 +2097,7 @@ int pp_define_env(const char * text, int len)
return 0;
}
-str *pp_define_get(int len, const char * text)
+str *pp_define_get(int len, const char *text)
{
str var = {(char *)text, len};
int i;
@@ -2129,7 +2139,7 @@ static int pp_ifdef_type(int type)
* ifndef defined -> 0
* ifndef undefined -> 1
*/
-static void pp_ifdef_var(int len, const char * text)
+static void pp_ifdef_var(int len, const char *text)
{
pp_ifdef_stack[pp_sptr] ^= (pp_lookup(len, text) < 0);
}
diff --git a/src/main.c b/src/main.c
index ee558db13f..6d363ba375 100644
--- a/src/main.c
+++ b/src/main.c
@@ -2202,16 +2202,17 @@ int main(int argc, char** argv)
case 'A':
p = strchr(optarg, '=');
if(p) {
- *p = '\0';
+ tmp_len = p - optarg;
+ } else {
+ tmp_len = strlen(optarg);
}
pp_define_set_type(0);
- if(pp_define(strlen(optarg), optarg)<0) {
+ if(pp_define(tmp_len, optarg)<0) {
fprintf(stderr, "error at define param: -A %s\n",
optarg);
goto error;
}
if(p) {
- *p = '=';
p++;
if(pp_define_set(strlen(p), p)<0) {
fprintf(stderr, "error at define value: -A %s\n",