]> git.ipfire.org Git - thirdparty/asterisk.git/commitdiff
Fix the REALTIME() dialplan function. ast_build_string() advances the string
authorRussell Bryant <russell@russellbryant.com>
Thu, 4 Jan 2007 04:33:00 +0000 (04:33 +0000)
committerRussell Bryant <russell@russellbryant.com>
Thu, 4 Jan 2007 04:33:00 +0000 (04:33 +0000)
pointer to the position to begin the next write into the buffer.  So, this
pointer can not be used to copy the contents of the string later.  The
beginning of the buffer must be saved.  Interestingly enough, this code could
not have ever worked.  (Pointed out by Sebb on IRC, thanks!)

git-svn-id: https://origsvn.digium.com/svn/asterisk/branches/1.4@49388 65c4cc65-6c06-0410-ace0-fbb531ad65f3

funcs/func_realtime.c

index 9610c0c2a39aa877b3af9183be64b21e90cd27dc..cab52a5883f7904dc5f20fffe6b210b602e14698 100644 (file)
@@ -49,7 +49,7 @@ static int function_realtime_read(struct ast_channel *chan, char *cmd, char *dat
 {
        struct ast_variable *var, *head;
         struct ast_module_user *u;
-       char *results;
+       char *results, *result_begin;
        size_t resultslen = 0;
        AST_DECLARE_APP_ARGS(args,
                AST_APP_ARG(family);
@@ -83,10 +83,10 @@ static int function_realtime_read(struct ast_channel *chan, char *cmd, char *dat
        for (var = head; var; var = var->next)
                resultslen += strlen(var->name) + strlen(var->value) + 2;
 
-       results = alloca(resultslen);
+       result_begin = results = alloca(resultslen);
        for (var = head; var; var = var->next)
                ast_build_string(&results, &resultslen, "%s%s%s%s", var->name, args.delim2, var->value, args.delim1);
-       ast_copy_string(buf, results, len);
+       ast_copy_string(buf, result_begin, len);
 
        ast_module_user_remove(u);