]> git.ipfire.org Git - thirdparty/asterisk.git/commitdiff
funcs/func_env: Fix regression caused in FILE read operation
authorMatthew Jordan <mjordan@digium.com>
Thu, 19 Mar 2015 19:20:21 +0000 (19:20 +0000)
committerMatthew Jordan <mjordan@digium.com>
Thu, 19 Mar 2015 19:20:21 +0000 (19:20 +0000)
When r432935 was merged, it did correctly fix a situation where a FILE read
operation on the middle of a file buffer would not read the requested length
in the parameters passed to the FILE function. Unfortunately, it would also
allow the FILE function to append more bytes than what was available in the
buffer if the length exceeded the end of the buffer length.

This patch takes the minimum of the remaining bytes in the buffer along with
the calculated length to append provided by the original patch, and uses
that as the length to append in the return result. This patch also updates
the unit tests with the scenarios that were originally pointed out in
ASTERISK-21765 that the original implementation treated incorrectly.

ASTERISK-21765
........

Merged revisions 433173 from http://svn.asterisk.org/svn/asterisk/branches/11
........

Merged revisions 433174 from http://svn.asterisk.org/svn/asterisk/branches/13

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

funcs/func_env.c
tests/test_func_file.c

index 0daa7f48d12f882639adfc2c619ce666d4870172..26bd09c139525f958a0ecad4d54a7b6ef0b9bc4d 100644 (file)
@@ -561,7 +561,7 @@ static int file_read(struct ast_channel *chan, const char *cmd, char *data, stru
 
                        /* Don't go past the length requested */
                        if (off_i + toappend > offset + length) {
-                               toappend = offset + length - off_i;
+                               toappend = MIN(offset + length - off_i, flength - off_i);
                        }
 
                        ast_str_append_substr(buf, len, fbuf, toappend);
index 4ebc87cafd0c56e9cb714d0605fa47888510a980..834907578a01e66ad331c8f2a2b11e325531501e 100644 (file)
@@ -63,6 +63,12 @@ static struct {
        /* No length */
        { "123456789", "-5", "56789" },
        { "123456789", "4", "56789" },
+       /* Passed file length */
+       { "123456789", "8,10", "9" },
+       { "123456789", "10,1", "" },
+       /* Middle of file */
+       { "123456789", "2,5", "34567" },
+       { "123456789", "-7,5", "34567" },
        /* Line mode, 4 ways of specifying the first character */
        { "123\n456\n789\n", "0,1,l", "123\n" },
        { "123\n456\n789\n", "-3,1,l", "123\n" },