On Thu, Jan 02, 2014 at 07:32:24PM -0000, SVN commits to the Digium 
repositories wrote:
> Author: sgriepentrog
> Date: Thu Jan  2 13:32:20 2014
> New Revision: 404674
> 
> URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=404674
> Log:
> func_strings: use memmove to prevent overlapping memory on strcpy
> 
> When calling REPLACE() with an empty replace-char argument, strcpy
> is used to overwrite the the matching <find-char>.  However as the
> src and dest arguments to strcpy must not overlap, it causes other
> parts of the string to be overwritten with adjacent characters and
> the result is mangled.  Patch replaces call to strcpy with memmove
> and adds a test suite case for REPLACE.
> 
> (closes issue ASTERISK-22910)
> Reported by: Gareth Palmer
> Patches:
>     func_strings.patch uploaded by Gareth Palmer (license 5169)
> 
> 
> Modified:
>     branches/1.8/funcs/func_strings.c
> 
> Modified: branches/1.8/funcs/func_strings.c
> URL: 
> http://svnview.digium.com/svn/asterisk/branches/1.8/funcs/func_strings.c?view=diff&rev=404674&r1=404673&r2=404674
> ==============================================================================
> --- branches/1.8/funcs/func_strings.c (original)
> +++ branches/1.8/funcs/func_strings.c Thu Jan  2 13:32:20 2014
[snip]

>                * directly there */
>               if (strchr(find, *strptr)) {
>                       if (ast_strlen_zero(replace)) {
> -                             /* Remove character */
> -                             strcpy(strptr, strptr + 1); /* SAFE */
> +                             memmove(strptr, strptr + 1, strlen(strptr + 1) 
> + 1);
>                               strptr--;
>                       } else {
>                               /* Replace character */
> @@ -1619,6 +1618,76 @@
>       return res;
>  }
>  
> +AST_TEST_DEFINE(test_REPLACE)

[snip]

> +             }
> +
> +             AST_LIST_INSERT_HEAD(ast_channel_varshead(chan), var, entries);

ast_channel_varshead does not exist in 1.8. This fails the builds.

s/ast_channel_varshead(chan)/&chan->varshead/ ?

http://svn.asterisk.org/svn/asterisk/trunk@357542

> +
> +             snprintf(expression, sizeof(expression), 
> "${REPLACE(%s,%s,%s)}", var->name, test_args[i].find_chars, 
> test_args[i].replace_char);
> +             ast_str_substitute_variables(&str, 0, chan, expression);
> +
> +             AST_LIST_REMOVE(ast_channel_varshead(chan), var, entries);

likewise.

-- 
               Tzafrir Cohen
icq#16849755              jabber:tzafrir.co...@xorcom.com
+972-50-7952406           mailto:tzafrir.co...@xorcom.com
http://www.xorcom.com

-- 
_____________________________________________________________________
-- Bandwidth and Colocation Provided by http://www.api-digital.com --

asterisk-dev mailing list
To UNSUBSCRIBE or update options visit:
   http://lists.digium.com/mailman/listinfo/asterisk-dev

Reply via email to