]> git.ipfire.org Git - thirdparty/asterisk.git/commitdiff
don't crash when asked to read from a file that doesn't exist (issue #6786)
authorRussell Bryant <russell@russellbryant.com>
Thu, 23 Mar 2006 20:13:48 +0000 (20:13 +0000)
committerRussell Bryant <russell@russellbryant.com>
Thu, 23 Mar 2006 20:13:48 +0000 (20:13 +0000)
git-svn-id: https://origsvn.digium.com/svn/asterisk/branches/1.2@14462 65c4cc65-6c06-0410-ace0-fbb531ad65f3

apps/app_readfile.c

index 3340964b7f277a68f5dffb0ff17398f3efd66dfd..bc418aaa17956b3b478af94c337cb1566f0b4806 100644 (file)
@@ -95,15 +95,16 @@ static int readfile_exec(struct ast_channel *chan, void *data)
                }
        }
 
-       returnvar = ast_read_textfile(file);
-       if(len > 0){
-               if(len < strlen(returnvar))
-                       returnvar[len]='\0';
-               else
-                       ast_log(LOG_WARNING,"%s is longer than %d, and %d \n", file, len, (int)strlen(returnvar));
+       if ((returnvar = ast_read_textfile(file))) {
+               if (len > 0) {
+                       if (len < strlen(returnvar))
+                               returnvar[len]='\0';
+                       else
+                               ast_log(LOG_WARNING, "%s is longer than %d, and %d \n", file, len, (int)strlen(returnvar));
+               }
+               pbx_builtin_setvar_helper(chan, varname, returnvar);
+               free(returnvar);
        }
-       pbx_builtin_setvar_helper(chan, varname, returnvar);
-       free(returnvar);
        LOCAL_USER_REMOVE(u);
        return res;
 }