]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
endless recursion loop protection to go with new recursive variable expansion feature
authorAnthony Minessale <anthm@freeswitch.org>
Thu, 12 Apr 2012 12:23:08 +0000 (07:23 -0500)
committerAnthony Minessale <anthm@freeswitch.org>
Thu, 12 Apr 2012 12:23:08 +0000 (07:23 -0500)
src/include/switch_channel.h
src/include/switch_event.h
src/switch_channel.c
src/switch_event.c

index 6b9d0e169751897c631599c4dc1ad7b6c6f1189a..37bb6f110220e68829e584b3721385f0126b1ab6 100644 (file)
@@ -593,8 +593,8 @@ SWITCH_DECLARE(void) switch_channel_event_set_extended_data(_In_ switch_channel_
   \return the original string if no expansion takes place otherwise a new string that must be freed
   \note it's necessary to test if the return val is the same as the input and free the string if it is not.
 */
-SWITCH_DECLARE(char *) switch_channel_expand_variables_check(switch_channel_t *channel, const char *in, switch_event_t *var_list, switch_event_t *api_list);
-#define switch_channel_expand_variables(_channel, _in) switch_channel_expand_variables_check(_channel, _in, NULL, NULL)
+SWITCH_DECLARE(char *) switch_channel_expand_variables_check(switch_channel_t *channel, const char *in, switch_event_t *var_list, switch_event_t *api_list, uint32_t recur);
+#define switch_channel_expand_variables(_channel, _in) switch_channel_expand_variables_check(_channel, _in, NULL, NULL, 0)
 
 
 SWITCH_DECLARE(char *) switch_channel_build_param_string(_In_ switch_channel_t *channel, _In_opt_ switch_caller_profile_t *caller_profile,
index c77e4aebb4a58fbfad75aa3c4f71547ff9cc9c94..13debb4b6bd37835bfeaef23e072ab2512b95ccf 100644 (file)
@@ -330,8 +330,8 @@ SWITCH_DECLARE(switch_status_t) switch_event_add_body(switch_event_t *event, con
 
 SWITCH_DECLARE(switch_status_t) switch_event_set_body(switch_event_t *event, const char *body);
 
-SWITCH_DECLARE(char *) switch_event_expand_headers_check(switch_event_t *event, const char *in, switch_event_t *var_list, switch_event_t *api_list);
-#define switch_event_expand_headers(_event, _in) switch_event_expand_headers_check(_event, _in, NULL, NULL)
+SWITCH_DECLARE(char *) switch_event_expand_headers_check(switch_event_t *event, const char *in, switch_event_t *var_list, switch_event_t *api_list, uint32_t recur);
+#define switch_event_expand_headers(_event, _in) switch_event_expand_headers_check(_event, _in, NULL, NULL, 0)
 
 SWITCH_DECLARE(switch_status_t) switch_event_create_pres_in_detailed(_In_z_ char *file, _In_z_ char *func, _In_ int line,
                                                                                                                                         _In_z_ const char *proto, _In_z_ const char *login,
index 0380f422db475406f4ded909f6594f5ab3629d4d..b6032d73f21eab1071b82e766b971eb41085019f 100644 (file)
@@ -3345,7 +3345,7 @@ SWITCH_DECLARE(switch_status_t) switch_channel_perform_answer(switch_channel_t *
        memset(c, 0, olen - cpos);\
        }}                           \
 
-SWITCH_DECLARE(char *) switch_channel_expand_variables_check(switch_channel_t *channel, const char *in, switch_event_t *var_list, switch_event_t *api_list)
+SWITCH_DECLARE(char *) switch_channel_expand_variables_check(switch_channel_t *channel, const char *in, switch_event_t *var_list, switch_event_t *api_list, uint32_t recur)
 {
        char *p, *c = NULL;
        char *data, *indup, *endof_indup;
@@ -3354,6 +3354,10 @@ SWITCH_DECLARE(char *) switch_channel_expand_variables_check(switch_channel_t *c
        char *func_val = NULL, *sb = NULL;
        int nv = 0;
 
+       if (recur > 100) {
+               return (char *) in;
+       }
+
        if (zstr(in)) {
                return (char *) in;
        }
@@ -3483,7 +3487,7 @@ SWITCH_DECLARE(char *) switch_channel_expand_variables_check(switch_channel_t *c
                                        char *ptr;
                                        int idx = -1;
                                        
-                                       if ((expanded = switch_channel_expand_variables_check(channel, (char *) vname, var_list, api_list)) == vname) {
+                                       if ((expanded = switch_channel_expand_variables_check(channel, (char *) vname, var_list, api_list, recur+1)) == vname) {
                                                expanded = NULL;
                                        } else {
                                                vname = expanded;
@@ -3508,7 +3512,7 @@ SWITCH_DECLARE(char *) switch_channel_expand_variables_check(switch_channel_t *c
                                                        sub_val = "INVALID";
                                                }
 
-                                               if ((expanded_sub_val = switch_channel_expand_variables(channel, sub_val)) == sub_val) {
+                                               if ((expanded_sub_val = switch_channel_expand_variables_check(channel, sub_val, var_list, api_list, recur+1)) == sub_val) {
                                                        expanded_sub_val = NULL;
                                                } else {
                                                        sub_val = expanded_sub_val;
@@ -3547,13 +3551,13 @@ SWITCH_DECLARE(char *) switch_channel_expand_variables_check(switch_channel_t *c
                                        if (stream.data) {
                                                char *expanded_vname = NULL;
                                                
-                                               if ((expanded_vname = switch_channel_expand_variables_check(channel, (char *) vname, var_list, api_list)) == vname) {
+                                               if ((expanded_vname = switch_channel_expand_variables_check(channel, (char *) vname, var_list, api_list, recur+1)) == vname) {
                                                        expanded_vname = NULL;
                                                } else {
                                                        vname = expanded_vname;
                                                }
 
-                                               if ((expanded = switch_channel_expand_variables_check(channel, vval, var_list, api_list)) == vval) {
+                                               if ((expanded = switch_channel_expand_variables_check(channel, vval, var_list, api_list, recur+1)) == vval) {
                                                        expanded = NULL;
                                                } else {
                                                        vval = expanded;
index dc4168687e8455e6988127573ec518d8aeca609a..deb972a0902a567877ae800bcbbeef61de5dda62 100644 (file)
@@ -1992,7 +1992,7 @@ if ((dp = realloc(data, olen))) {\
     memset(c, 0, olen - cpos);\
  }}                           \
 
-SWITCH_DECLARE(char *) switch_event_expand_headers_check(switch_event_t *event, const char *in, switch_event_t *var_list, switch_event_t *api_list)
+SWITCH_DECLARE(char *) switch_event_expand_headers_check(switch_event_t *event, const char *in, switch_event_t *var_list, switch_event_t *api_list, uint32_t recur)
 {
        char *p, *c = NULL;
        char *data, *indup, *endof_indup;
@@ -2003,6 +2003,10 @@ SWITCH_DECLARE(char *) switch_event_expand_headers_check(switch_event_t *event,
        int nv = 0;
        char *gvar = NULL, *sb = NULL;
 
+       if (recur > 100) {
+               return (char *) in;
+       }
+
        if (zstr(in)) {
                return (char *) in;
        }
@@ -2132,7 +2136,7 @@ SWITCH_DECLARE(char *) switch_event_expand_headers_check(switch_event_t *event,
                                        char *ptr;
                                        int idx = -1;
                                        
-                                       if ((expanded = switch_event_expand_headers_check(event, (char *) vname, var_list, api_list)) == vname) {
+                                       if ((expanded = switch_event_expand_headers_check(event, (char *) vname, var_list, api_list, recur+1)) == vname) {
                                                expanded = NULL;
                                        } else {
                                                vname = expanded;
@@ -2162,7 +2166,7 @@ SWITCH_DECLARE(char *) switch_event_expand_headers_check(switch_event_t *event,
                                                }
 
 
-                                               if ((expanded_sub_val = switch_event_expand_headers(event, sub_val)) == sub_val) {
+                                               if ((expanded_sub_val = switch_event_expand_headers_check(event, sub_val, var_list, api_list, recur+1)) == sub_val) {
                                                        expanded_sub_val = NULL;
                                                } else {
                                                        sub_val = expanded_sub_val;
@@ -2198,13 +2202,13 @@ SWITCH_DECLARE(char *) switch_event_expand_headers_check(switch_event_t *event,
                                        if (stream.data) {
                                                char *expanded_vname = NULL;
 
-                                               if ((expanded_vname = switch_event_expand_headers_check(event, (char *) vname, var_list, api_list)) == vname) {
+                                               if ((expanded_vname = switch_event_expand_headers_check(event, (char *) vname, var_list, api_list, recur+1)) == vname) {
                                                        expanded_vname = NULL;
                                                } else {
                                                        vname = expanded_vname;
                                                }
 
-                                               if ((expanded = switch_event_expand_headers_check(event, vval, var_list, api_list)) == vval) {
+                                               if ((expanded = switch_event_expand_headers_check(event, vval, var_list, api_list, recur+1)) == vval) {
                                                        expanded = NULL;
                                                } else {
                                                        vval = expanded;