Fix LEN segfault (bug #1228)
authorMark Spencer <markster@digium.com>
Fri, 19 Mar 2004 06:36:25 +0000 (06:36 +0000)
committerMark Spencer <markster@digium.com>
Fri, 19 Mar 2004 06:36:25 +0000 (06:36 +0000)
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@2469 65c4cc65-6c06-0410-ace0-fbb531ad65f3

pbx.c

diff --git a/pbx.c b/pbx.c
index 8de44ee..f033de9 100755 (executable)
--- a/pbx.c
+++ b/pbx.c
@@ -751,7 +751,20 @@ static void pbx_substitute_variables_temp(struct ast_channel *c,const char *var,
                headp=&c->varshead;
     *ret=NULL;
         /* Now we have the variable name on cp3 */
-       if ((first=strchr(var,':'))) {
+       if (!strncasecmp(var,"LEN(",4)) {
+               int len=strlen(var);
+               int len_len=4;
+               if (strrchr(var,')')) {
+                       char cp3[80];
+                       strncpy(cp3, var, sizeof(cp3) - 1);
+                       cp3[len-len_len-1]='\0';
+                       sprintf(workspace,"%d",strlen(cp3));
+                       *ret = workspace;
+               } else {
+                       /* length is zero */
+                       *ret = "0";
+               }
+       } else if ((first=strchr(var,':'))) {
                strncpy(tmpvar, var, sizeof(tmpvar) - 1);
                first = strchr(tmpvar, ':');
                if (!first)
@@ -929,17 +942,6 @@ static void pbx_substitute_variables_temp(struct ast_channel *c,const char *var,
                                }
                        }
                }
-               if (!(*ret) && !strncasecmp(var,"LEN(",4)) {
-                       int len=strlen(var);
-                       int len_len=4;
-                       if (len > (len_len+1) && !strncasecmp(var,"LEN(",len_len) && strchr(var+len_len+2,')')) {
-                               char cp3[80];
-                               strncpy(cp3, var, sizeof(cp3) - 1);
-                               cp3[len-len_len-1]='\0';
-                               sprintf(workspace,"%d",strlen(cp3));
-                               *ret = workspace;
-                       } else ast_log(LOG_NOTICE, "Wrong use of LEN(VARIABLE)\n");
-               }
        }
 }