]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
FS-8413: Segfault calling session:getVariable(nil) in lua script
authorMark Lipscombe <mlipscombe@gmail.com>
Wed, 4 Nov 2015 06:33:11 +0000 (17:33 +1100)
committerMichael Jerris <mike@jerris.com>
Mon, 9 Nov 2015 22:02:14 +0000 (16:02 -0600)
script calling session:getVariable() with a null variable
name will cause FreeSWITCH to segfault.

This change checks whether varname parameter to
switch_channel_get_variable_dup is non-NULL.

src/switch_channel.c

index a56a2eeb87a8bfdde165846b81f70e241be1a3c4..b9aa1d71fc47a935edad074c2e83ccbdc96a7393 100644 (file)
@@ -930,32 +930,34 @@ SWITCH_DECLARE(const char *) switch_channel_get_variable_dup(switch_channel_t *c
 
        switch_mutex_lock(channel->profile_mutex);
 
-       if (channel->scope_variables) {
-               switch_event_t *ep;
+       if (!zstr(varname)) {
+               if (channel->scope_variables) {
+                       switch_event_t *ep;
 
-               for (ep = channel->scope_variables; ep; ep = ep->next) {
-                       if ((v = switch_event_get_header_idx(ep, varname, idx))) {
-                               break;
+                       for (ep = channel->scope_variables; ep; ep = ep->next) {
+                               if ((v = switch_event_get_header_idx(ep, varname, idx))) {
+                                       break;
+                               }
                        }
                }
-       }
 
-       if (!v && (!channel->variables || !(v = switch_event_get_header_idx(channel->variables, varname, idx)))) {
-               switch_caller_profile_t *cp = switch_channel_get_caller_profile(channel);
+               if (!v && (!channel->variables || !(v = switch_event_get_header_idx(channel->variables, varname, idx)))) {
+                       switch_caller_profile_t *cp = switch_channel_get_caller_profile(channel);
 
-               if (cp) {
-                       if (!strncmp(varname, "aleg_", 5)) {
-                               cp = cp->originator_caller_profile;
-                               varname += 5;
-                       } else if (!strncmp(varname, "bleg_", 5)) {
-                               cp = cp->originatee_caller_profile;
-                               varname += 5;
+                       if (cp) {
+                               if (!strncmp(varname, "aleg_", 5)) {
+                                       cp = cp->originator_caller_profile;
+                                       varname += 5;
+                               } else if (!strncmp(varname, "bleg_", 5)) {
+                                       cp = cp->originatee_caller_profile;
+                                       varname += 5;
+                               }
                        }
-               }
 
-               if (!cp || !(v = switch_caller_get_field_by_name(cp, varname))) {
-                       if ((vdup = switch_core_get_variable_pdup(varname, switch_core_session_get_pool(channel->session)))) {
-                               v = vdup;
+                       if (!cp || !(v = switch_caller_get_field_by_name(cp, varname))) {
+                               if ((vdup = switch_core_get_variable_pdup(varname, switch_core_session_get_pool(channel->session)))) {
+                                       v = vdup;
+                               }
                        }
                }
        }