- use found pointer to compute the lenght of ID for -A parameter to save
a strlen()
... | ... |
@@ -1927,11 +1927,16 @@ ksr_ppdefine_t* pp_get_define(int idx) |
1927 | 1927 |
return &pp_defines[idx]; |
1928 | 1928 |
} |
1929 | 1929 |
|
1930 |
-static int pp_lookup(int len, const char * text) |
|
1930 |
+static int pp_lookup(int len, const char *text) |
|
1931 | 1931 |
{ |
1932 | 1932 |
str var = {(char *)text, len}; |
1933 | 1933 |
int i; |
1934 | 1934 |
|
1935 |
+ if(len<=0 || text==NULL) { |
|
1936 |
+ LM_ERR("invalid parameters"); |
|
1937 |
+ return -1; |
|
1938 |
+ } |
|
1939 |
+ |
|
1935 | 1940 |
for (i=0; i<pp_num_defines; i++) |
1936 | 1941 |
if (STR_EQ(pp_defines[i].name, var)) |
1937 | 1942 |
return i; |
... | ... |
@@ -1945,10 +1950,15 @@ int pp_define_set_type(int type) |
1945 | 1950 |
return 0; |
1946 | 1951 |
} |
1947 | 1952 |
|
1948 |
-int pp_define(int len, const char * text) |
|
1953 |
+int pp_define(int len, const char *text) |
|
1949 | 1954 |
{ |
1950 | 1955 |
int ppos; |
1951 | 1956 |
|
1957 |
+ if(len<=0 || text==NULL) { |
|
1958 |
+ LM_ERR("invalid parameters"); |
|
1959 |
+ return -1; |
|
1960 |
+ } |
|
1961 |
+ |
|
1952 | 1962 |
LM_DBG("defining id: %.*s\n", len, text); |
1953 | 1963 |
|
1954 | 1964 |
if (pp_num_defines == MAX_DEFINES) { |
... | ... |
@@ -2010,7 +2020,7 @@ int pp_define_set(int len, char *text) |
2010 | 2020 |
LM_BUG("BUG: the index in define table not set yet\n"); |
2011 | 2021 |
return -1; |
2012 | 2022 |
} |
2013 |
- if(len<=0) { |
|
2023 |
+ if(len<=0 || text==NULL) { |
|
2014 | 2024 |
LM_DBG("no define value - ignoring\n"); |
2015 | 2025 |
return 0; |
2016 | 2026 |
} |
... | ... |
@@ -2046,7 +2056,7 @@ int pp_define_set(int len, char *text) |
2046 | 2056 |
return 0; |
2047 | 2057 |
} |
2048 | 2058 |
|
2049 |
-int pp_define_env(const char * text, int len) |
|
2059 |
+int pp_define_env(const char *text, int len) |
|
2050 | 2060 |
{ |
2051 | 2061 |
char *r; |
2052 | 2062 |
str defname; |
... | ... |
@@ -2087,7 +2097,7 @@ int pp_define_env(const char * text, int len) |
2087 | 2097 |
return 0; |
2088 | 2098 |
} |
2089 | 2099 |
|
2090 |
-str *pp_define_get(int len, const char * text) |
|
2100 |
+str *pp_define_get(int len, const char *text) |
|
2091 | 2101 |
{ |
2092 | 2102 |
str var = {(char *)text, len}; |
2093 | 2103 |
int i; |
... | ... |
@@ -2129,7 +2139,7 @@ static int pp_ifdef_type(int type) |
2129 | 2139 |
* ifndef defined -> 0 |
2130 | 2140 |
* ifndef undefined -> 1 |
2131 | 2141 |
*/ |
2132 |
-static void pp_ifdef_var(int len, const char * text) |
|
2142 |
+static void pp_ifdef_var(int len, const char *text) |
|
2133 | 2143 |
{ |
2134 | 2144 |
pp_ifdef_stack[pp_sptr] ^= (pp_lookup(len, text) < 0); |
2135 | 2145 |
} |
... | ... |
@@ -2202,16 +2202,17 @@ int main(int argc, char** argv) |
2202 | 2202 |
case 'A': |
2203 | 2203 |
p = strchr(optarg, '='); |
2204 | 2204 |
if(p) { |
2205 |
- *p = '\0'; |
|
2205 |
+ tmp_len = p - optarg; |
|
2206 |
+ } else { |
|
2207 |
+ tmp_len = strlen(optarg); |
|
2206 | 2208 |
} |
2207 | 2209 |
pp_define_set_type(0); |
2208 |
- if(pp_define(strlen(optarg), optarg)<0) { |
|
2210 |
+ if(pp_define(tmp_len, optarg)<0) { |
|
2209 | 2211 |
fprintf(stderr, "error at define param: -A %s\n", |
2210 | 2212 |
optarg); |
2211 | 2213 |
goto error; |
2212 | 2214 |
} |
2213 | 2215 |
if(p) { |
2214 |
- *p = '='; |
|
2215 | 2216 |
p++; |
2216 | 2217 |
if(pp_define_set(strlen(p), p)<0) { |
2217 | 2218 |
fprintf(stderr, "error at define value: -A %s\n", |